【问题标题】:WebSocket opening handshake timed outWebSocket 打开握手超时
【发布时间】:2015-12-09 11:27:57
【问题描述】:

我正在开发一个 Google Cloud Compute Engine 实例。 Ubuntu 12.04。 我在服务器上安装了一个 Tornado 应用程序,在端口 8888 上工作,并且我的 nginx 配置如下所示:

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

upstream chat_servers {
    server 127.0.0.1:8888;
}

server {
    listen 80;
    server_name chat.myapp.com;

    access_log /home/ubuntu/logs/nginx_access.log;
    error_log /home/ubuntu/logs/nginx_error.log;

    location /talk/ {
        proxy_set_header X-Real-IP $remote_addr;  # http://wiki.nginx.org/HttpProxyModule
        proxy_set_header Host $host;  # pass the host header - http://wiki.nginx.org/HttpProxyModule#proxy_pass
        proxy_http_version 1.1;  # recommended with keepalive connections - http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version
        # WebSocket proxying - from http://nginx.org/en/docs/http/websocket.html
        proxy_connect_timeout 7d;
        proxy_send_timeout 7d;
        proxy_read_timeout 7d;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_pass       http://chat_servers;

    }
}

当我尝试通过 Javascript 连接到 ws://chat.myapp.com/talk/etc/ 时,Tornado 应用程序在 WebSocketHandler 上的 open() 方法被调用,我在服务器上成功打印了日志,但在客户端,代码永远不会进入 @987654325 @ 一段时间后,我得到1006 error code,WebSocket 打开握手超时`。

这个应用程序在具有相同配置的 Amazon (AWS) EC2 服务器上运行良好,但在我迁移到 Google Cloud 后,不知何故无法完成握手。

是否有任何特定于 Google Cloud 的配置?或者文件上有任何 nginx 更新?

我很困惑,我花了两天时间解决了这个问题。

【问题讨论】:

    标签: nginx websocket tornado google-compute-engine google-cloud-platform


    【解决方案1】:

    Ubuntu 上默认的 nginx 版本是nginx/1.1.19。我将其更新为nginx/1.8.0。问题解决了。

    【讨论】:

      猜你喜欢
      • 2019-12-22
      • 1970-01-01
      • 2023-03-05
      • 2019-11-04
      • 2019-06-11
      • 1970-01-01
      • 2017-03-19
      • 2023-03-08
      • 2015-01-28
      相关资源
      最近更新 更多