Nginx seems to ignore proxy_set_header Host directive

Francis Daly francis at daoine.org
Mon Feb 11 21:43:45 UTC 2013


On Mon, Feb 11, 2013 at 04:13:28PM -0500, jeangouytch wrote:

Hi there,

> > 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.
> > 
> Ok, I think i'm not using the right words, maybe "rewriting" is not the
> exact term. My problem is :
> relative path for images are normal in the html files, looking like
> "/media/myimage.jpg"
> I understand that the proxy_set_header directive would make the relative
> path to be treated as serverIP/pyload/media/myimage.jpg,

No, proxy_set_header doesn't do that. http://nginx.org/r/proxy_set_header
for details of what it does do.

I don't know of any reliable way to get nginx to correctly change the
content of html files, and anything else that the browser might interpret
as containing local urls, so that everything works as you wish.

The easiest two ways of proxying multiple servers are: convince the
"pyload" server that all of its content is *actually* below /pyload,
so that it generates "correct" urls itself (and do something similar for
each other internal server); or use different hostnames for each internal
server, and have different server{} blocks in nginx.conf proxy_pass to
different internal servers.

The third way is to ensure that all of the content on all of the internal
servers never refers to any local url that starts with "/" -- so instead
of "/media/myimage.jpg" it would be "../../media/myimage.jpg", with the
correct number of "../" components each time.

The first two ways are "matching subdirectories on the proxy and proxied
servers"; the third is "great care on the proxied server".

If you have a restricted, controlled set of file contents on each server,
then you might be able to use one of the substitution filter modules to
make enough changes that it works well enough for you.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list