本文主要记录一下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


codecraft
11.9k 声望2k 粉丝

当一个代码的工匠回首往事时,不因虚度年华而悔恨,也不因碌碌无为而羞愧,这样,当他老的时候,可以很自豪告诉世人,我曾经将代码注入生命去打造互联网的浪潮之巅,那是个很疯狂的时代,我在一波波的浪潮上留下...