我设法在我的基础设施(Webfactions)上部署流星.
应用程序似乎工作正常,但是当我的应用程序启动时,我在浏览器控制台中收到以下错误:
WebSocket连接到’ws://…/websocket’失败:WebSocket握手中出错:意外响应代码:400
最佳答案
WebSockets很快,你不必(不应该)禁用它们.
原文链接:https://www.f2er.com/nginx/435206.html这个错误的真正原因是Webfactions使用Nginx,并且Nginx配置不正确.这里是如何correctly configure nginx to proxy WebSocket requests,通过设置proxy_set_header升级$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;
}
}
这是基于David Weldon’s nginx config的改进的Nginx配置.安卓毛泽东已经达到了very similar configuration.
记住还要将HTTP_FORWARDED_COUNT环境变量设置为应用程序前的代理数(通常为1).