# Trying to get something like proxypassreverse going

**URL:** <https://www.ruby-forum.com/t/trying-to-get-something-like-proxypassreverse-going/193531>\
**Category:** NGINX\
**Created:** [August 19, 2010, 10:54am UTC](https://www.ruby-forum.com/t/trying-to-get-something-like-proxypassreverse-going/193531 "2010-08-19T10:54:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90db22/32.png) [@Tim\_U](https://www.ruby-forum.com/u/Tim_U)\
**Post date:** [August 19, 2010, 10:54am UTC](https://www.ruby-forum.com/t/trying-to-get-something-like-proxypassreverse-going/193531/1 "2010-08-19T10:54:48Z")

</div>

Hey all.

I am trying to get proxy a certain path in my domain to a different  
back end than the “normal” paths. So far I have done this. I got all  
this information from various sites on the web and it almost works.

proxy\_redirect off;  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
client\_max\_body\_size 10m;  
client\_body\_buffer\_size 128k;  
client\_header\_buffer\_size 64k;  
proxy\_connect\_timeout 90;  
proxy\_send\_timeout 90;  
proxy\_read\_timeout 90;  
proxy\_buffer\_size 16k;  
proxy\_buffers 32 16k;  
proxy\_busy\_buffers\_size 64k;

proxy\_pass\_header Set-Cookie;  
proxy\_pass\_header P3P;

server {  
listen 80;  
server\_name [my.server.com](http://my.server.com);  
location / {  
proxy\_pass [http://localhost:3001](http://localhost:3001);  
}  
location /foo/ {  
proxy\_pass [http://localhost:3000/](http://localhost:3000/);  
}  
}

This works except that some sort of a rewrite rule is required because  
the links form that back end are broken. For example when the backend  
links to /images/blah or /stylesheets/blah the browser thinks the  
images and the stylesheets come from the / root.

I would like the proxy to somehow rewrite those links to be  
/foo/images/blah and /foo/stylesheets/blah.

I saw this link… [http://wiki.nginx.org/NginxLikeApache](http://wiki.nginx.org/NginxLikeApache) but that does  
not work at all.

Any help would be much appreciated.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Tim\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90db22/32.png) [@Tim\_U](https://www.ruby-forum.com/u/Tim_U)\
**Post date:** [August 21, 2010, 8:47am UTC](https://www.ruby-forum.com/t/trying-to-get-something-like-proxypassreverse-going/193531/2 "2010-08-21T08:47:26Z")

</div>

Hey guys I hate to bump my own post but…

I am still struggling to get this proxy going. I have followed example  
after example on the web and nothing seems to work. I have also read  
through the documentation on proxy\_pass and proxy\_redirect but I still  
can’t make it work.

What I am trying to do is pretty simple I think and surely this is a  
solved problem.

Here is the situation.

I have a rails site. Initially I was serving with passenger but I  
changed it to a proxy because I thought maybe passenger was causing a  
problem. I am now using nginx without the passenger module.

The main web site is being served from the backend [http://localhost:3001](http://localhost:3001)  
This part works great. I can go to [my.server.com](http://my.server.com) and I get the web site  
I am expecting.

I want anything in the /foo path to be handled by backend  
[http://localhost:3000](http://localhost:3000) This almost works. Then I browse  
[http://my.server.com/foo](http://my.server.com/foo) it sends the request to the proper backend but  
the stylesheets, images etc don’t load. The reason is because the links  
from the backend point to /stylesheets, /images etc and nginx is not  
proxying these.

Somehow I need nginx to append /foo to /stylesheets when they come from  
localhost:3000

According to the documantation the proxy redirect is supposed to do this  
but I can’t find the magic incantation. The documentation says …

Let us suppose the proxied server returned line Location:  
[http://localhost:8000/two/some/uri/](http://localhost:8000/two/some/uri/).

The directive

proxy\_redirect [http://localhost:8000/two/](http://localhost:8000/two/) [http://frontend/one/](http://frontend/one/);

will rewrite this line in the form Location:  
[http://frontend/one/some/uri/](http://frontend/one/some/uri/).

In the replaceable line it is possible not to indicate the name of the  
server:

proxy\_redirect [http://localhost:8000/two/](http://localhost:8000/two/) /;

then the basic name of server and port is set, if it is different from  
80.

I tried this but I still can’t make it work.

Surely there is an easy way to this pretty simple thing.

Posted at Nginx Forum:

> **[Re: trying to get something like proxypassreverse going.](https://forum.nginx.org/read.php?2,121239,122018#msg-122018)**
>
> Hey all. I am trying to get proxy a certain path in my domain to a different back end than the "normal" paths. So far I have done this. I got all this information from various sites on the web and it almost works. proxy\_redirect off;
