What does the Resolver param in nginx do?

guyyug picture guyyug · Oct 30, 2016 · Viewed 38.9k times · Source

I am using nginx as a reverse_proxy server with ELB. I am looking for explanation regarding the resolver value I set in the nginx.conf file. My nginx.conf:

http {  
   ...

   resolver x.x.x.x valid=30s;

   ...
}

server {

   ...

   set $elb "example.com";

location / { 
    ...

    rewrite ^/(.*) $1 break;
    proxy_pass http://$elb/$1?$args; 

    ...
   }
   ...    
}  

I followed this - https://www.ruby-forum.com/topic/6816375#1166569 and set /etc/resolv.conf value as the resolver value and it works fine. What is standing behind this?

Answer

Dmitry MiksIr picture Dmitry MiksIr · Oct 30, 2016

The nginx resolver directive is required because the system resolver blocks. Nginx is a multiplexing server (many connections in one OS process), so each call of system resolver will stop processing all connections till the resolver answer is received. That's why Nginx implemented its own internal non-blocking resolver.

If your config file has static DNS names (not generated), and you do not care about track IP changes without nginx reload, you don't need nginx's resolver. In this case all DNS names will be resolved on startup.

Nginx's resolver should be used, if you want to resolve domain name in runtime without nginx reload.