【问题标题】:How to redirect websocket session with an Nginx proxy to an IBM Bluemix webapp?如何将带有 Nginx 代理的 websocket 会话重定向到 IBM Bluemix webapp?
【发布时间】:2017-12-30 01:26:42
【问题描述】:

这是我的 nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log debug;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {

    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    upstream websocket {
        server myapp.onbluemix.net:80;
    }

    server {
       listen 80;
       location / {
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection $connection_upgrade;  
             proxy_pass http://websocket;
           }
    }
}

我可以从 nginx 代理服务器 ping 我在 bluemix 上的 web 应用程序。

这里是 nginx 的日志

HTTP/1.1 500 Error
Server: nginx/1.13.3
Content-Type: text/xml
Transfer-Encoding: chunked
Connection: keep-alive  
X-Backside-Transport: FAIL FAIL

我将 webapp 的 IP 地址添加到 nginx 的 hosts 文件中以防万一,同样的错误。

如果我在本地机器上运行 webapp,Nginx 代理可以工作。

我不明白那个断言X-Backside-Transport: FAIL FAIL

怎么了?

【问题讨论】:

    标签: nginx websocket proxy ibm-cloud


    【解决方案1】:

    似乎涉及到内部 IBM Proxy,您必须在标头 (proxy_set_header host myapp.onbluemix.net;) 中添加要访问的主机,例如:

    location / {
        proxy_http_version 1.1;
        proxy_set_header host myapp.onbluemix.net;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;  
        proxy_pass http://websocket;
    }  
    

    【讨论】:

      猜你喜欢
      • 2018-09-21
      • 2015-11-02
      • 2020-10-03
      • 1970-01-01
      • 1970-01-01
      • 2018-02-22
      • 1970-01-01
      • 2018-02-08
      • 2019-06-26
      相关资源
      最近更新 更多