Converting subdomain to path component without redirect ?

Francis Daly francis at
Sat May 4 21:48:34 UTC 2013

On Mon, Apr 29, 2013 at 10:02:35PM +0100, henrique matias wrote:

Hi there,

> Am having trouble setting up my nginx.config to transparently proxy the
> subdomains and domains to the same app, but with different "path
> components" appended to the $uri

Frequently, the main problem is that the back-end application makes it
very hard to do this.

I suggest you test first using a separate server{} block for one
server_name and demonstrate to yourself that it can work.

After that, you can worry about the details of how to auto-handle the
extra domains.

Something like (untested):

  server {
    location / {
      proxy_pass http://app_server/it/;

maybe with "proxy_set_header Host;", or whatever your
application needs.

The important things to check are, do links in the returned content work
when the browser asks for "/dir/" but the app_server gets a request for

The above is *almost* the same as what you have here:

> This is my last unsuccessful attempt:

but there's an extra "/" in the proxy_pass line; and as you've not said
in what way yours was unsuccessful, it's hard to suggest a specific fix.

Compare the output of "curl -i"
with the output of "curl -i", and with
what you expect the output to be.

Francis Daly        francis at

More information about the nginx mailing list