Nginx seems to ignore proxy_set_header Host directive

Hi all

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

For example, owncloud server with apache, pyload with it’s builtin http
server, xbmc web interface, …

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

Here’s a simple conf file for nginx.

########################################################
server {
listen 80; ## listen for ipv4; this line is default and
implied

    root /hdd/www;
    index index.html index.htm;

    server_name localhost;

    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 http://192.168.1.100:8001/;
    }

}
########################################################

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.

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

Regards

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,236099,236099#msg-236099

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 http://192.168.1.100:8001/;
    }

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 (http://nginx.org/r/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
proxy_pass.

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 http://nginx.org/r/sub_filter if you think you want to change
the content.)

f

Francis D. [email protected]

Hi Francis. Thank you for your help.

proxy_pass.

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.

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, but the chrome
console shows that the relative path are treated as
serverIP/media/myimage.jpg

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,236099,236115#msg-236115

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 D. [email protected]

Ok, thank you for making the things clear. I’ll try to go with the first
solution then.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,236099,236124#msg-236124

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs