NGINX will always use a resolver to resolve a domain name to its corresponding IP address. Sometimes, especially for testing, it would be great if we can ask NGINX to resolve a domain name based on some temporary entries added to the /etc/hosts file. To do that, we need the help of dnsmasq application.
First, let’s install it.
Edit the domain name to IP address mapping.
Restart dnsmasq.
Now, we have a resolver set up. It will first resolve the domain name using the /etc/hosts file. If not found, it will forward the request to the system-wide resolver stated in the /etc/resolv.conf.
Now, let’s configure the NGINX to make use of the dnsmasq.
Add the following entry.
resolver 127.0.0.1;
Restart NGINX.
Now, the NGINX will look up the entries in the /etc/hosts before using the system-wide resolver.