Proxying header question

Igor Sysoev is at rambler-co.ru
Sun Apr 1 11:19:42 MSD 2007


On Sat, Mar 31, 2007 at 10:43:51PM -0400, Wayne E. Seguin wrote:

> On Mar 31, 2007, at 16:26 , Igor Sysoev wrote:
> 
> >On Fri, Mar 23, 2007 at 07:40:03PM -0400, Wayne E. Seguin wrote:
> >
> >>I'm trying to setup dynamic handling based on the subdomain asked for
> >>in an application that is proxied to.
> >>
> >>Basically I'm using:
> >>
> >>upstream http://domain.tld {
> >
> >-upstream http://domain.tld {
> >+upstream domain.tld {
> >
> >>...
> >>}
> >>
> >>server {
> >>  location / {
> >>    proxy_set_header  X-Real-IP  $remote_addr;
> >>    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
> >>    proxy_set_header Host $http_host;
> >
> >-     proxy_set_header Host $http_host;
> >+     proxy_set_header Host $host;
> >
> >>    proxy_redirect false;
> >
> >-     proxy_redirect false;
> >+     proxy_redirect off;
> >
> >>    proxy_max_temp_file_size 0;
> >>...
> >>    if (!-f $request_filename) {
> >>      proxy_pass http://domain.tld;
> >>      break;
> >>    }
> >>  }
> >>}
> >>
> >>What I'm finding is that the requested url "subdomain.domain.tld"
> >>doesn't pass through, instead I only get "domain.tld".
> >>
> >>Is there a way to tell Nginx to pass this through?
> >>I've scanned the wiki but have not found this yet in there.
> >
> >The subdomain.domain.tld is on the same physical host as the  
> >domain.tld ?
> 
> Igor,
> 
> Thank you very much for your response.
> 
> For three subdomains domains yes same physical host for two of the  
> subdomains they are on two other physical hosts.

Then you should use the following configuration:

http {
    ...

    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  Host $host;
    proxy_redirect off;
    proxy_max_temp_file_size 0;

    server {
        server_name  domain.tld;

        location / {
            if (!-f $request_filename) {
                proxy_pass  http://backend.domain.tld;
                break;
            }
        }
    }

    server {
        server_name  subdomain1.domain.tld;

        location / {
            if (!-f $request_filename) {
                proxy_pass  http://backend.subdomain1.domain.tld;
                break;
            }
        }
    }

    ...

You can not one "server" to proxy to same physical hosts, because you
use "if (!-f $request_filename)" - you mix "/index.html" of one host
with other hosts.


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list