[case2] note a nginx host not found exception.

  nginx

Order

This article mainly records the host not found exception of nginx.

Background

A certain internal domain name can be used on machines A and B, but cannot be resolved on machine C. nginx starts to report an error.

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

resolver

What should I do? nginx’s resolver designation will come in handy. Check their dns on machines a and b.

➜  ~ 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

Configure nginx dns

        location /fix-dns {
            resolver 192.168.100.1 valid=300s;
            set $demohost demo.com.cn;
            proxy_pass http://$demohost/api/xxx ;
        }

Of course, resolver can also be placed under the server module according to the situation.

doc