前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nginx: [emerg] host not found in upstream "cdn.xieboke.net" in /usr/local/nginx/conf/vhost/joyo.ink.

nginx: [emerg] host not found in upstream "cdn.xieboke.net" in /usr/local/nginx/conf/vhost/joyo.ink.

作者头像
卓越笔记
发布2023-02-18 15:47:23
5380
发布2023-02-18 15:47:23
举报
文章被收录于专栏:卓越笔记

错误日志

代码语言: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
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-3-25 1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 错误日志
  • systemd 配置文件
  • nginx 配置文件
  • 解决办法
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档