javascript - 将 ExpressJS 与 nginx 一起使用时出现 502 Bad Gateway

标签 javascript nginx websocket express nowjs-sockets

如果我像这样运行我的 expressjs 应用程序:coffee server.coffee 并导航到 localhost:8080,一切正常。

但是,当我使用以下配置使用 nginx 反向代理 8080 时:

server {
    listen 0.0.0.0:80;
    server_name localhost;
    access_log /var/log/nginx/nodetest.log;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://node/;
      proxy_redirect off;
    }
}

upstream node {
    server 127.0.0.1:8080;
}

我在 Chrome 开发控制台中收到以下错误:

GET http://184.73.217.204/socket.io/xhr-polling//1300750540040 502(错误网关)

以及 nginx 的 error.log

中的以下内容
2011/03/22 13:07:59 [error] 10269#0: *18 upstream prematurely closed connection while
reading response header from upstream, client: 168.229.58.68, server: localhost, 
request:     "GET /socket.io/xhr-polling//1300799281533 HTTP/1.1", upstream:     
"http://127.0.0.1:8080/socket.io/xhr-polling/1300799281533", host: "184.73.217.204",    
referrer: "http://184.73.217.204/"

感谢任何指导!

最佳答案

试试这个补丁...

    -proxy_pass http://node/;
    +proxy_pass http://node;

关于javascript - 将 ExpressJS 与 nginx 一起使用时出现 502 Bad Gateway,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5385036/

相关文章:

websocket - Golang Server关闭客户端连接: websocket

javascript - 根据屏幕大小和父 div 位置定位子 div

javascript - 我可以强制对话框只能在窗口内拖动吗?

PHP-FPM With Opcache 尝试打开其他池的缓存文件

node.js - NodeJS - 返回客户端 ip 地址而不是服务器的

websocket - 如何防止websocket在angular5中的特定时间后关闭?

c# - 在 Windows Azure 上运行 Fleck(或任何)Websocket 服务器

javascript - jquery 加载函数在 chrome 中不起作用,而在 firefox 中起作用?

javascript - 如何在 html5 网络应用程序中禁用 android 后退按钮单击

python - 上传大文件 nginx + uwsgi