Nginx - Faking host Header

To pass through the Host: header to the reverse proxied app, add the following to your server / location block:

proxy_set_header Host $host;

It depends on the nginx virtual host configuration what are the possible values for $host eventually.

If your server block is a default_server block, it means the server block will process any requests sent to any virtual host. In that case the value of Host header propagates to upstream server.

To prevent that in the default_server scenario, use this version:

proxy_set_header Host example.com;

where example.com is your domain name.

Even better is to configure nginx properly so that default_server block always returns 404 for example, and a proper virtualhost with correct name is used.