【发布时间】: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