# Nginx seems to ignore proxy\_set\_header Host directive

**URL:** <https://www.ruby-forum.com/t/nginx-seems-to-ignore-proxy-set-header-host-directive/229519>\
**Category:** NGINX\
**Created:** [February 11, 2013, 4:44pm UTC](https://www.ruby-forum.com/t/nginx-seems-to-ignore-proxy-set-header-host-directive/229519 "2013-02-11T16:44:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeangouytch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e47774/32.png) [@jeangouytch](https://www.ruby-forum.com/u/jeangouytch)\
**Post date:** [February 11, 2013, 4:44pm UTC](https://www.ruby-forum.com/t/nginx-seems-to-ignore-proxy-set-header-host-directive/229519/1 "2013-02-11T16:44:31Z")

</div>

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:

> **[Nginx seems to ignore proxy\_set\_header Host directive](https://forum.nginx.org/read.php?2,236099,236099#msg-236099)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![jeangouytch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e47774/32.png) [@jeangouytch](https://www.ruby-forum.com/u/jeangouytch)\
**Post date:** [February 11, 2013, 8:10pm UTC](https://www.ruby-forum.com/t/nginx-seems-to-ignore-proxy-set-header-host-directive/229519/2 "2013-02-11T20:10:18Z")

</div>

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 ([Module ngx\_http\_proxy\_module](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 [Module ngx\_http\_sub\_module](http://nginx.org/r/sub_filter) if you think you want to change  
the content.)

## f

Francis D. removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jeangouytch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e47774/32.png) [@jeangouytch](https://www.ruby-forum.com/u/jeangouytch)\
**Post date:** [February 11, 2013, 10:14pm UTC](https://www.ruby-forum.com/t/nginx-seems-to-ignore-proxy-set-header-host-directive/229519/3 "2013-02-11T22:14:15Z")

</div>

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:

> **[Re: Nginx seems to ignore proxy\_set\_header Host directive](https://forum.nginx.org/read.php?2,236099,236115#msg-236115)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![jeangouytch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e47774/32.png) [@jeangouytch](https://www.ruby-forum.com/u/jeangouytch)\
**Post date:** [February 11, 2013, 10:44pm UTC](https://www.ruby-forum.com/t/nginx-seems-to-ignore-proxy-set-header-host-directive/229519/4 "2013-02-11T22:44:05Z")

</div>

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](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. removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jeangouytch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e47774/32.png) [@jeangouytch](https://www.ruby-forum.com/u/jeangouytch)\
**Post date:** [February 12, 2013, 8:55am UTC](https://www.ruby-forum.com/t/nginx-seems-to-ignore-proxy-set-header-host-directive/229519/5 "2013-02-12T08:55:07Z")

</div>

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

Posted at Nginx Forum:

> **[Re: Nginx seems to ignore proxy\_set\_header Host directive](https://forum.nginx.org/read.php?2,236099,236124#msg-236124)**
>
> 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...
