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

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


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.


A workaround is to use Nginx map, in order to copy the /etc/hosts content.

map $wanted_host $wanted_host_ip{    default 127.0.0.1;    b.dev.local X.X.X.X;    a.dev.local X.X.X.X;}server{    listen              80;    server_name         ~^(?P<wanted_port>[0-9]+?)-(?P<wanted_host>.+?)\.HOSTNAME$;    location /    {        proxy_pass http://$wanted_host_ip:$wanted_port;    }}

This will map wanted_hostto wanted_host_ip , like a resolver.