Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the Resolver param in nginx do?

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?

like image 996
guyyug Avatar asked Oct 30 '16 15:10

guyyug


People also ask

What does Nginx resolver do?

Specifies the name servers that should be employed by Nginx to resolve hostnames to IP addresses and vice-versa. DNS query results are cached for some time, either by respecting the TTL provided by the DNS server, or by specifying a time value to the valid argument.

What is Proxy_buffering in nginx?

Proxy buffering is enabled by default in NGINX (the proxy_buffering directive is set to on ). Proxy buffering means that NGINX stores the response from a server in internal buffers as it comes in, and doesn't start sending data to the client until the entire response is buffered.

What does upstream do in nginx?

NGINX is a load-balancing tool widely used in the IT industry. It is a web server that can be used as a reverse proxy, mail proxy, or an HTTP cache. Upstream is a module used in NGINX to define the servers to be load balanced.

How does nginx reverse proxy work?

A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.


2 Answers

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.

like image 98
Dmitry MiksIr Avatar answered Oct 09 '22 22:10

Dmitry MiksIr


Nginx resolver directive is critical to any AWS environment that relies on ELB and proxy_pass. Here is the post that I wrote recently describing problem and solutions to the static DNS caching by opensource nginx:

Nginx resolver explained and how to deal with changing IPs

Basically it will boil down to following config for simple case:

server {
  listen        80;
  server_name   example.com;

  location / {

    resolver 172.16.0.23;

    set $upstream_endpoint http://service-999999.eu-west-2.elb.amazonaws.com;

    proxy_pass $upstream_endpoint$request_uri;
  }
}
like image 17
gansbrest Avatar answered Oct 09 '22 20:10

gansbrest