Reverse proxy : preserving base url

Francis Daly francis at
Mon Apr 15 18:05:28 UTC 2013

On Sat, Apr 13, 2013 at 10:35:47PM -0400, mastah wrote:

Hi there,

>    I've a sub domain which we will call :
>    I've an internal application at
> What I would like :
>    I would like to proxy to and i want to
> keep my URL as
>    So far I've done countless try without success.

There are two distinct parts to this.

You have the http headers, and you have the body (which will be html or
css or jpg or something else).

nginx can reasonably be expected to adjust the response http headers.

nginx can't reasonably be expected to adjust the response body.

Unless you put in special configuration, nginx with proxy_pass will
probably adjust the response headers for you.

You can try to adjust the body. You will have to match every string
that your client browser will interpret as a url, and make sure that it
works when the browser considers it relative to the non-/app/ url that
it started with.

> The optimal situation would be that when I do :
> I get the content from
> but without any change in the sub domain URL.
> So for example if the internal app has
>, my sub domain should be
> (without app/)

The cleanest way to achieve this is for you to configure your application
either (a) to believe that it is installed at "/", not at "/app/"; or
(b) to never create any links that start with "/".

In each of those cases, the browser should interpret relative links
correctly without nginx having to modify any body content.

(If you use option (b) and create links like "../../../app/other/place",
then that will break this. So don't do that.)

Francis Daly        francis at

More information about the nginx mailing list