During an epic debugging session with an NGinx configuration for a project,
I discovered some useful, but not so common (at least to me) configuration.
Debug
NGinx do not provide so much help (by default) when it comes to debugging internal redirect,
proxying and other rewrite rules. But it comes with a handy debug module which allows you
to get a lot more info.
NGinx is well known for its proxy/reverse-proxy/caching-proxy capabilities, but
you’d better know how some things works to not waste your time on some odd
behaviors.
When proxying to remote host by URLs, be aware that NGinx use its own internal resolver for DNS name.
This means in some cases it can’t resolve domains unless you specify which DNS to use.
This example is fully working because we used an IP address for $remote_download_url,
but if we were using the domain (eg: download.mydomain.tld), any request would fail
with a 502 Bad Gateway error.
This is due to the way NGinx default resolver works. It’s smart enough to resolve
the domains in proxy_pass directives as long as they are statics (it can get them
at boot time) and they are in /etc/hosts. But as we are constructing the URL here,
it does not try to resolve it. Fortunately you can specify which DNS server
it should use in such cases by setting: