2012-08-15 111 views
1

我有两个监听器80和777.端口80充当反向代理。而端口777做了一些额外的东西,并希望重定向到端口80.如何重定向到Nginx中的不同端口?我与重写尝试,但后来想通了,它仅用于路径的变化将请求重定向到不同的监听器nginx

### 
    server{ 
      listen 80; 
      server_name  _; 
      location/{ 
        proxy_pass "http://upstream0;#" is included since links are not allowed in the post 
      } 

    } 

    server{ 
      listen 777; 
      server_name  _; 
      #doing some other extra stuf 
      //Want to redirect to port 80 under some condition 
    } 

这可能吗?

感谢

回答

0

尽可能nginx的关注有路过的东西到另一个nginx的监听器/服务器和传球成才OT阿帕奇/杂种/薄/ ...或任何其他HTTP服务器 换句话说,没有真正的区别如果您想通过到其它监听传递的东西,你会使用proxy_pass

所以你想要做的是一样的东西

location/{ 
    if (some condition) { 
    proxy_pass http://$host:80 
    } 
} 

看到http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

+0

proxy_pass在if条件中是不允许的,您应该使用location/{proxy_pass http:// $ host:80; } – 2014-04-26 15:47:14

+0

根据上面的链接文档,proxy_pass指令允许的上下文之一是“if in location”,更新示例以明确指出 – cobaco 2014-04-29 17:30:44

+0

这也不起作用,它在文档中不可用,我试过了它之前。 – 2014-04-29 20:51:56

相关问题