Nginx seems to ignore proxy_set_header Host directive

Francis Daly francis at
Mon Feb 11 19:09:39 UTC 2013

On Mon, Feb 11, 2013 at 10:44:03AM -0500, jeangouytch wrote:

Hi there,

> I am trying to use nginx to get remote access to various service on my home
> server, via proxy_pass redirection to various subdirectorys

That's fairly standard. Although having different levels of subdirectories
on the proxied and the proxy servers usually gets messy, unless the
proxied server is very careful.

> I access the webserver via a static IP adress, and not via a domain name.

The "listen" and "server_name" directives determine which "server"
is used for each request.  So using an IP address is fine, so long as
things are set correctly.

(The easy way to ensure that, is to have exactly one server{} block.)

>         location /pyload/ {
>                 proxy_redirect off;
>                 proxy_set_header Host $host;
>                 proxy_set_header X-Real-IP $remote_addr;
>                 proxy_set_header X-Forwarded-For $remote_addr;
>                 proxy_pass;
>         }

> I think this setup would be straighforward, but for some reason, all
> relative path are not rewriten and I get 502 error for all images, css and
> js file.

Which relative paths?  How do you want them to be rewritten?

What part of the nginx config do you expect will do the rewriting?

And how does that match the subject of this mail?

proxy_redirect ( can do rewriting of
http headers, except you've turned it off here.

proxy_set_header doesn't do rewriting of anything. Neither does

> I would be very grateful if someone had a clue to help me understanding what
> I am doing wrong.

Can you give an example of what you do, what you see, and what you
expect to see? "curl -i" is usually a good way of showing the headers
and content returned.

(*Usually*, it's best if nginx does not mess with the content. You can
look at if you think you want to change
the content.)

Francis Daly        francis at

More information about the nginx mailing list