2012-10-11 94 views
7

我想Nginx的一个子域配置为代理的东西:dev.int.comNginx的配置与proxy_pass

我想dev.int.com代理到IP:8080,和dev.int。 COM /藏匿代理到IP:7990

这是我目前的配置文件

server { 
listen 80; 
server_name dev.int.com; 
access_log off; 
location/{ 
    proxy_pass http://IP:8080; 
    proxy_set_header Host   $host; 
    proxy_set_header X-Real-IP  $remote_addr; 
    proxy_set_header X-Forwarded-for $remote_addr; 
    port_in_redirect off; 
    proxy_redirect http://IP:8080/jira /; 
    proxy_connect_timeout 300; 
    location ~ ^/stash { 
     proxy_pass http://IP:7990; 
     proxy_set_header Host   $host; 
     proxy_set_header X-Real-IP  $remote_addr; 
     proxy_set_header X-Forwarded-for $remote_addr; 
     port_in_redirect off; 
     proxy_redirect http://IP:7990/ /stash; 
     proxy_connect_timeout 300; 
    } 
} 

    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
    root /usr/local/nginx/html; 
    } 
} 

然而,/藏匿重定向要去/。我究竟做错了什么?

回答

16

试试这个...

server { 
    listen 80; 
    server_name dev.int.com; 
    access_log off; 
    location/{ 
     proxy_pass http://IP:8080; 
     proxy_set_header Host   $host; 
     proxy_set_header X-Real-IP  $remote_addr; 
     proxy_set_header X-Forwarded-for $remote_addr; 
     port_in_redirect off; 
     proxy_redirect http://IP:8080/jira /; 
     proxy_connect_timeout 300; 
    } 

    location ~ ^/stash { 
     proxy_pass http://IP:7990; 
     proxy_set_header Host   $host; 
     proxy_set_header X-Real-IP  $remote_addr; 
     proxy_set_header X-Forwarded-for $remote_addr; 
     port_in_redirect off; 
     proxy_redirect http://IP:7990/ /stash; 
     proxy_connect_timeout 300; 
    } 

    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root /usr/local/nginx/html; 
    } 
} 
+0

嗨,还是重定向到的/不是/藏匿 – bear

+0

嘿 - 好看看这个家伙的conf文件。他有两个服务器条目可以帮助你解决问题。 http://stackoverflow.com/questions/1174554/setting-up-subdomains-on-nginx –