# Re: trying to get something like proxypassreverse going

**URL:** <https://www.ruby-forum.com/t/re-trying-to-get-something-like-proxypassreverse-going/193672>\
**Category:** NGINX\
**Created:** [August 21, 2010, 5:45pm UTC](https://www.ruby-forum.com/t/re-trying-to-get-something-like-proxypassreverse-going/193672 "2010-08-21T17:45:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![c1sc0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e5b9ba/32.png) [@c1sc0](https://www.ruby-forum.com/u/c1sc0)\
**Post date:** [August 21, 2010, 5:45pm UTC](https://www.ruby-forum.com/t/re-trying-to-get-something-like-proxypassreverse-going/193672/1 "2010-08-21T17:45:53Z")

</div>

“timuckun” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Hi there,

> 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.

You probably have it working perfectly for the HTTP headers, which is  
what  
both apache proxypassreverse and nginx proxy\_redirect handle. What you  
seem to want is a way to additionally modify the HTTP response body –  
the main stuff that the backend application sends.

In order to do that, you’ll likely need a body filter. But it’s almost  
certainly much much easier just to configure the backend application  
not to need that filter.

> 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.

For clarity:

the browser asks nginx “get [http://my.server.com/foo/](http://my.server.com/foo/)”; nginx asks the  
backend “get [http://localhost:3000/](http://localhost:3000/)”; the backend replies with some  
headers (which may include the string “localhost:3000”) and the body;  
nginx sends the headers (possibly modified, possibly with the string  
“localhost:3000” replaced with the string “[my.server.com/foo](http://my.server.com/foo)”) and the  
body (probably unmodified) to the browser.

“the links from the backend” that you are concerned about are within  
the html – in the body, which nginx didn’t touch.

Can you configure the backend (using something like a “baseurl” option)  
to believe that it is installed at /foo, so that it will write the image  
links as /foo/images?

Alternatively, can you configure or write the backend application never  
to  
start local links with “/”, but instead to use exactly the correct  
number  
of "…/"s so that all local links are relative to the starting  
location? That would allow the browser to correctly create the correct  
full urls.

If that is impossible, then can you install the backend to be at  
[http://localhost:3000/foo](http://localhost:3000/foo)? Again, that should get the internal links to  
have the desired “local part” of the url.

If that is also impossible, then you may need to get into writing the  
body filter.

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

If you can get localhost:3000 to generate the correct-for-you links,  
it’ll be easier.

> According to the documantation the proxy redirect is supposed to do this

No.

> 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/).

Yes.

Assume that “/images” is a browseable directory on the backend. Then:

the browser asks nginx “get [http://my.server.com/foo/images](http://my.server.com/foo/images)”; nginx  
asks the backend “get [http://localhost:3000/images](http://localhost:3000/images)”; the backend  
replies with a HTTP redirect to “[http://localhost:3000/images/](http://localhost:3000/images/)” (or  
possibly to just “/images/”); nginx rewrites that Location: header to be  
“[http://my.server.com/foo/images/](http://my.server.com/foo/images/)” and sends it to the browser.

The browser then asks “get [http://my.server.com/foo/images/](http://my.server.com/foo/images/)”; nginx  
asks “get [http://localhost:3000/images/](http://localhost:3000/images/)”; the backend replies with  
the directory listing wrapped in html (typically); nginx sends that to  
the browser.

All works well, because no links written in the html body content were  
followed.

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

Arrange that the backend application generates the correct-for-you urls  
directly. That way, nginx doesn’t have to do any special processing of  
the body content, and it can just do what it does best.

Good luck with it,

## f

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

---

<div class="post-metadata">

**Author:** ![c1sc0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e5b9ba/32.png) [@c1sc0](https://www.ruby-forum.com/u/c1sc0)\
**Post date:** [August 22, 2010, 2:54am UTC](https://www.ruby-forum.com/t/re-trying-to-get-something-like-proxypassreverse-going/193672/2 "2010-08-22T02:54:54Z")

</div>

> Arrange that the backend application generates the correct-for-you urls  
> directly. That way, nginx doesn’t have to do any special processing of  
> the body content, and it can just do what it does best.
> 
> Good luck with it,
> 
> ## Â Â Â Â f
> 
> Francis D. Â Â Â Â [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Thanks Francis for that concise and extremely clear explanation of  
what is going on. I now know where to go proceed.
