我设法在我的基础设施(Webfactions)上部署 Meteor。
该应用程序似乎工作正常,但当我的应用程序启动时,我在浏览器控制台中收到以下错误:
WebSocket connection to 'ws://.../websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
WebSocket 速度很快,您不必(也不应该)禁用它们。
造成这个错误的真正原因是Webfactions使用了nginx,而nginx配置不当。以下是如何正确配置 nginx 来代理 WebSocket 请求 http://nginx.org/en/docs/http/websocket.html, 通过设置proxy_set_header Upgrade $http_upgrade;
and 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;
}
}
这是基于 nginx 配置的改进David Weldon 的 nginx 配置 https://stackoverflow.com/questions/18003689/recommended-nginx-configuration-for-meteor。毛泽东已经达到了非常相似的配置 https://stackoverflow.com/a/24497020/1269037.
请记住还要设置HTTP_FORWARDED_COUNT http://docs.meteor.com/#/full/meteor_onconnection环境变量设置为应用程序前面的代理数量(通常为 1)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)