proxy_pass无法正常工作

时间:2014-04-02 17:51:06

标签: nginx proxy gunicorn bosh converse.js

我需要为我们团队的项目设置解决一些跨域政策问题(Converse.js, XMPP,BOSH,...)通过设置nginx反向代理配置。

我想完全准备这些绑定:

  • nginx到本地gunicorn HTTP服务器 http://my.nginx.server.com/应代理http://localhost:8000/

  • nginx到BOSH的远程HTTP服务器 http://my.nginx.server.com/http-bind应代理http://some.very.remote.server:5280/http-bind

目前,只有第一个绑定有效。第二个不是。 nginx将每个请求传递给本地gunicorn HTTP服务器,而不是远程服务器。

这是我的nginx.conf:

...
server {
    listen       80;
    server_name  localhost;

    # Reverse proxy for remote HTTP server
    location ~ ^/http-bind/ {
        proxy_pass http://some.very.remote.server:5280;
    }

    # Reverse proxy for local gunicorn HTTP server
    location / {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect http://$server_name http://$server_name:8000;
    }
    ...
}

1 个答案:

答案 0 :(得分:0)

我找到了这个有效的配置:

        location /http-bind {
            proxy_pass http://sapbot.mo.sap.corp:5280/http-bind;
            proxy_set_header Host $host;
            proxy_buffering off;
            tcp_nodelay on;
        }

        location / {
            proxy_pass http://localhost:8000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect http://$server_name http://$server_name:8000;
        }