[case2]记一个nginx host not found异常

本文主要记录一下nginx的host not found异常

背景

某个内部域名,在A,B机器都可以,但是在C机器解析不了,nginx启动报错

nginx: [emerg] host not found in upstream "demo.com.cn" in /usr/local/openresty/nginx/conf/nginx.conf:95

resolver

怎么办了,这下nginx的resolver指定就派上用场了。在A,B机器上查看他们的dns

➜  ~ cat /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 192.168.100.1

配置nginx dns

        location /fix-dns {
            resolver 192.168.100.1 valid=300s;
            set $demohost demo.com.cn;
            proxy_pass http://$demohost/api/xxx ;
        }
当然也可以根据情况将resolver放在server模块底下。

doc

  • resolver
  • resolver_timeout
  • nginx dns resolver配置方法示例

你可能感兴趣的:(nginx)