gpa*_*sse 19 nginx node.js meteor
我设法在我的基础设施(Webfactions)上部署meteor.该应用程序似乎工作正常但我在应用程序启动时在浏览器控制台中收到以下错误:
WebSocket connection to 'ws://.../websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
Dan*_*scu 54
WebSockets速度很快,您不必(也不应该)禁用它们.
此错误的真正原因是Webfactions使用nginx,并且nginx配置不正确.下面介绍如何正确配置nginx的来代理的WebSocket请求,通过设置proxy_set_header Upgrade $http_upgrade;和proxy_set_header Connection $connection_upgrade;:
# we're in the http context here
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# the Meteor / Node.js app server
server {
server_name yourdomain.com;
access_log /etc/nginx/logs/yourapp.access;
error_log /etc/nginx/logs/yourapp.error error;
location / {
proxy_pass http://localhost:3000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
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_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
Run Code Online (Sandbox Code Playgroud)
这是基于David Weldon的nginx配置的改进的nginx配置.Andrew Mao已经达到了非常相似的配置.
还要记住将HTTP_FORWARDED_COUNT环境变量设置为应用程序前面的代理数量(通常为1).
如果您在浏览器控制台中收到此错误客户端,则可以放心地忽略它 - 这意味着您的主机不支持websockets,而meteor将回退使用长轮询
部署到heroku或没有websockets的任何其他平台的meteor应用程序将得到相同的错误
更新:从meteor v0.6.4开始,您现在可以设置环境变量,DISABLE_WEBSOCKETS以防止在您知道失败时发生此尝试
https://github.com/meteor/meteor/blob/devel/History.md
If you set the DISABLE_WEBSOCKETS environment variable, browsers will not attempt to connect to your app using Websockets. Use this if you know your server environment does not properly proxy Websockets to reduce connection startup time.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18054 次 |
| 最近记录: |