Nginx 提示host not found in upstream 错误解决方法

nginx的upstream配置如下:

upstream nos {
    server nos.xxx.com weight=10 max_fails=3 fail_timeout=30s;
}

检查语法报错:

root@ubuntu:~/odd/nginx/sbin# ./nginx -t
nginx: [emerg] host not found in upstream "nos.xxx.com" in /root/odd/nginx/conf/upstream/nos.conf:5
nginx: configuration file /root/odd/nginx/conf/nginx.conf test failed

猜测是dns解析域名失败,:

root@ubuntu:~/odd/nginx/sbin# ping wwww.baidu.com
ping: unknown host wwww.baidu.com

ping百度不通,无法上外网。检查/etc/resolv.conf,发现没有配置域名服务器,增加域名服务器:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.4.4

重启网络:

root@ubuntu:~/odd/nginx/sbin# /etc/init.d/networking restart
[ ok ] Restarting networking (via systemctl): networking.service.

重新检查nginx语法:

root@ubuntu:~/odd/nginx/sbin# ./nginx -t
nginx: the configuration file /root/odd/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /root/odd/nginx/conf/nginx.conf test is successful

ok,现在成功了!

你可能感兴趣的:(openresty,openresty)