【发布时间】:2016-03-14 19:22:47
【问题描述】:
我们正在尝试在 Nginx 后面的 Debian 服务器上运行 Meteor 应用程序。应用程序正在运行,但 http://url/sockjs?info?cb=[random_string] 的 GET 请求返回 502 Bad Gateway。
Nginx 配置是这样设置的:
# this section is needed to proxy web-socket connections
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream app_server {
server 127.0.0.1:3000; # for a web port socket (we'll use this first)
# server unix:/var/run/app/app.sock;
}
server {
listen 80;
server_name app_server.com;
charset utf-8;
client_max_body_size 75M;
access_log /var/log/nginx/app.access.log;
error_log /var/log/nginx/app.error.log;
location / {
proxy_pass http://app_server;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP
proxy_read_timeout 60s;
keepalive_timeout 65;
proxy_redirect off;
# the root path (/) MUST NOT be cached
if ($uri != '/') {
expires 30d;
}
}
}
我们尝试了各种配置,但无法找出故障所在。 Meteor WebSocket handshake error 400 with nginx 的解决方案也不起作用。
编辑:尝试了在recommended nginx configuration for meteor找到的以下配置,它仍然返回502。
编辑:该应用程序在不从 Meteor CFS 获取图像时工作正常,Meteor CFS 用于通过管理仪表板存储上传的图像。加载图像时,对 domain/sockjs/img_location/cb/xhr_send 的 POST 会导致 502 错误。
【问题讨论】:
-
也许尝试更改 proxy_pass 以指向您的流星实例并删除上游 app_server?除非您需要负载平衡,否则我想...proxy_pass localhost:3000;也可以看看这个资源:meteorpedia.com/read/nginx
-
@Sparticus 之前尝试过该配置,结果相同。
-
我注意到您使用的是
proxy_set_header Connection $connection_upgrade;...您是否尝试使用proxy_set_header Connection $http_connection;代替? -
@Myst 是的,试过了,但仍然遇到同样的错误。已编辑问题并提供额外的调查输入。
-
你使用的是什么构建包?