Reverse proxy : preserving base url
francis at daoine.org
Mon Apr 15 18:05:28 UTC 2013
On Sat, Apr 13, 2013 at 10:35:47PM -0400, mastah wrote:
> I've a sub domain which we will call : sub.example.com
> I've an internal application at 127.0.0.1:9090/app
> What I would like :
> I would like to proxy sub.example.com to 127.0.0.1:9090/app and i want to
> keep my URL as sub.example.com
> 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 :
> http://sub.example.com/ I get the content from http://127.0.0.1:9090/app
> but without any change in the sub domain URL.
> So for example if the internal app has
> http://127.0.0.1:9090/app/magical.css, my sub domain should be
> http://sub.example.com/magical.css (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 daoine.org
More information about the nginx