错误日志
代码语言:javascript复制[root@VM_2_29_centos ~]# systemctl status nginx -l
● nginx.service - nginx
Loaded: loaded (/etc/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2021-03-25 16:27:52 CST; 7min ago
Process: 493 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=1/FAILURE)
Mar 25 16:27:52 VM_2_29_centos systemd[1]: Starting nginx...
Mar 25 16:27:52 VM_2_29_centos nginx[493]: nginx: [emerg] host not found in upstream "cdn.xieboke.net" in /usr/local/nginx/conf/vhost/joyo.ink.conf:38
Mar 25 16:27:52 VM_2_29_centos systemd[1]: nginx.service: control process exited, code=exited status=1
Mar 25 16:27:52 VM_2_29_centos systemd[1]: Failed to start nginx.
Mar 25 16:27:52 VM_2_29_centos systemd[1]: Unit nginx.service entered failed state.
Mar 25 16:27:52 VM_2_29_centos systemd[1]: nginx.service failed.
systemd 配置文件
代码语言:javascript复制vim /etc/systemd/system/uwsgi.service
代码语言:javascript复制[Unit]
Description=uwsgi
After=network.target
[Service]
Type=notify
ExecStart=/root/.virtualenvs/joyoo/bin/uwsgi --ini /root/yzq/djangos/blog/blog_uwsgi.ini
ExecReload=/root/.virtualenvs/joyoo/bin/uwsgi --reload /root/yzq/running/uwsgi_joyoo.pid
ExecStop=/root/.virtualenvs/joyoo/bin/uwsgi --stop /root/yzq/running/uwsgi_joyoo.pid
Restart=always
[Install]
WantedBy=multi-user.target
代码语言:javascript复制# 重载系统服务,因添加了 nginx.server
sudo systemctl daemon-reload
# 启动 nginx
sudo systemctl start nginx
# 停止 nginx
sudo systemctl stop nginx
# 查看 nginx 状态
sudo systemctl status nginx
# 设置开机启动
sudo systemctl enable nginx
# 取消开机启动
sudo systemctl disable nginx
nginx 配置文件
nginx -t 都是没问题的
代码语言:javascript复制[root@VM_2_29_centos ~]# cat /usr/local/nginx/conf/vhost/joyo.ink.conf
server {
listen 80;
# listen 443;
server_name joyo.ink www.joyo.ink;
charset utf-8;
client_max_body_size 50m;
# ssl on;
# ssl_certificate /root/yzq/djangos/blog/certificate/xiebole.net/Nginx/1_xieboke.net_bundle.crt;
# ssl_certificate_key /root/yzq/djangos/blog/certificate/xiebole.net/Nginx/2_xieboke.net.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
access_log /root/yzq/logs/joyo.ink.access.log;
error_log /root/yzq/logs/joyo.ink.error.log;
if ($server_port = "443") {
return 302 http://$host$request_uri;
}
location / {
uwsgi_pass 127.0.0.1:9090;
include uwsgi_params;
# root html;
# index index.html index.htm;
}
location /media {
alias /root/yzq/djangos/blog/media;
}
location /static {
# alias /root/yzq/djangos/blog/static_root;
proxy_pass http://cdn.xieboke.net/static_root;
# rewrite /static/(.*) http://cdn.xieboke.net/static_root/$1;
}
}
[root@VM_2_29_centos ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
利用 nginx 进行反向代理的时候,我们会配置 proxy_pass。在启动 nginx 的时候,会报:
nginx: [emerg] host not found in upstream "cdn.xieboke.net" in /usr/local/nginx/conf/vhost/joyo.ink.conf:38
其实 nginx 配置语法上没有错误的,只是系统无法解析这个域名,所以报错。
解决办法
就添加 dns 到 /etc/resolv.conf 或者是 /etc/hosts, 让其能够解析到IP。
具体步骤如下:
代码语言:javascript复制vim /etc/hosts
修改hosts文件,在hosts文件里面加上一句
代码语言:javascript复制127.0.0.1 localhost.localdomain cdn.xieboke.net