Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using proxy_pass, can /etc/hosts be used to resolve domain names instead of "resolver"?

Can /etc/hosts be used instead of resolver when using proxy_pass?

I need to perform a proxy_pass to the same nginx machine. Is there a way to resolve the domains using the machine's /etc/hosts file instead of specifying a DNS server thru the "resolver" property?

This will save me the additional hops needed to reach the same server. I have tried setting up the internal IP mapped to the DNS in /etc/hosts file but nginx is still reading from the DNS server set in the resolver property. Or is there a way to make the HTTPProxy module to consider the /etc/hosts file settings?

Thanks for any advice you could share..

This is the same question I posted in the nginx forum: http://forum.nginx.org/read.php?11,218997

like image 223
Ianthe the Duke of Nukem Avatar asked Nov 29 '11 02:11

Ianthe the Duke of Nukem


People also ask

Does nslookup use etc hosts?

nslookup is not coded to consult the /etc/nsswitch. conf file, and it is not able to resolve hostnames or addresses that are in the local /etc/hosts file.

Does nslookup bypass hosts file?

A generic host lookup (i.e. gethostbyname() can go via the hosts file, or via DNS, but a DNS-specific lookup (as performed by nslookup ) will not use the hosts file.


1 Answers

You can get around this by installing dnsmasq and setting your resolver to 127.0.0.1. Basically this uses your local DNS as a resolver, but it only resolves what it knows about (among those things is your /etc/hosts) and forwards the rest to your default DNS.

like image 71
Mikael Karon Avatar answered Sep 19 '22 18:09

Mikael Karon