[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

    原文作者:codecraft
    原文地址: https://segmentfault.com/a/1190000012836121
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞