Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx resolver -- dns

Please excuse a very beginner question.

I'm having trouble understanding the nginx 'resolver' parameter and how it works. I have read the documentation, searched tutorials and posts (using keywords like resolver, nginx, and dns), and I'm still not sure how to apply resolver.

http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver

"Configures name servers used to resolve names of upstream servers into addresses...."

  • By this definition, it seems to be simply doing the nameserver's job. resolver ns1.myhost.com ns2.myhost.com; But the examples point to an internal/private IP address.

"An address can be specified as a domain name or IP address, and an optional port...."

  • This implies that I could resolver example.com www.example.com; (or resolver 12.34.56.78;) but again, I see no such examples in the documentation.

As a practical example, let's say — purely hypothetically :) — that I'm building a simple web server with a couple of server blocks on it.

Do I set 'resolver' to the IP of the server itself? Or an internal IP in the server's LAN? The documentation seems to suggest an internal IP (127.x.x.x or 10.x.x.x) — but how to set/determine what that IP is?

like image 466
Geekomancer Avatar asked Apr 04 '18 02:04

Geekomancer


1 Answers

Resolve means which DNS server nginx should refer to when it has to resolve an external url. If you have a config like below

location / {
    proxy_pass http://www.example.com/abc/def; 
}

Now by default nginx will pick your resolver from the host /etc/resolv.conf, but it may not be what you need. If you want to use the Google DNS resolver, then you will update your nginx config like below:

location / {
    resolver 8.8.8.8;
    proxy_pass http://www.example.com/abc/def; 
}

If you are using a local DNS resolver to route within your local network, then you may use something like below:

location / {
    resolver 192.168.11.10;
    proxy_pass http://machineabc/abc/def; 
}
like image 74
Tarun Lalwani Avatar answered Sep 23 '22 13:09

Tarun Lalwani