Proxy_pass and slash witch nginx

Igor Sysoev igor at sysoev.ru
Fri May 20 15:06:58 MSD 2011


On Thu, May 19, 2011 at 04:37:38PM -0400, myckeul wrote:
> Hello,
> 
> Thanks for your response but they won't working.

> my vhost : 
> server {
>        listen [::]:80;
> 
>        server_name proxy.com *.proxy.com;
> 
>        access_log  /var/log/nginx/proxy_.access.log;
> 
>        error_page 404 = /404.htm;
> 
>        location /404.htm {
>        	root /var/www;
>        }
> 
>        location / {
>        		proxy_set_header X-Forwarded-Host $host;
> 		proxy_set_header X-Forwarded-Server $host;
> 		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> 
> 
> 		if ($host ~* ^proxy\.com$) {
> 		   proxy_pass http://mydomain.com;
> 		}
> 
> 		if ($host ~* ^www\.proxy\.com$) {
> 		   proxy_pass http://www.mydomain.com;
> 		}
> 
> 		if ($host ~* ^subdomain\.proxy\.com$) {
> 		   proxy_pass http://subdomain.mydomain.com;
> 		}
> 
> 		proxy_redirect http://proxy.com/test http://proxy.com/test/;
> 	}
> }

proxy_redirect http://mydomain.com http://proxy.com;
proxy_redirect http://www.mydomain.com http://www.proxy.com;
proxy_redirect http://subdomain.mydomain.com http://subdomain.proxy.com;

BTW, your configuraiton is wrong mix of levels: you should not use
virtual host name on location level in "if ($host ~". This leads
to cumbersome and unmaintainable configurations.
Instead you should define 3 separate servers:

server {
      server_name  proxy.com;
      location / {
          proxy_pass  http://mydomain.com;
      }
      ...
}

server {
      server_name  www.proxy.com;
      location / {
          proxy_pass  http://www.mydomain.com;
      }
      ...
}

server {
      server_name  subdomain.proxy.com;
      location / {
          proxy_pass  http://subdomain.mydomain.com;
      }
      ...
}


-- 
Igor Sysoev



More information about the nginx mailing list