本文介绍了“响应代码:502"表示“使用带有proxy_pass的socket.io和nginx 1.4.x(稳定)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在nginx下运行我的应用程序(使用socket.io),并且在服务器端出现WebSocket connection to 'ws://...' failed: Unexpected response code: 502错误.自从v.1.3以来,我已经读过nginx支持websocket,所以我只是升级到了nginx v1.4.1 (stable).

I am trying to make running my app (using socket.io) under nginx, and i get an WebSocket connection to 'ws://...' failed: Unexpected response code: 502 error on the server side.I have read that nginx suport the websockets since the v.1.3 so i just have upgrade to the nginx v1.4.1 (stable).

这是我的朋友:

server {
       listen 80;
       server_name website.com;

        location / {
          proxy_pass    http://127.0.0.1:3000;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          access_log    /var/log/nginx/website/access.log;
          error_log    /var/log/nginx/website/error.log;
        }
}

更新:

我不得不说我可以访问应用程序(所以我确实监听端口3000),除非出现此错误,否则socket.io可以正常工作,但是在某些情况下,emit调用不会发送任何参数,所以我得到undefined.

I have to say that i can reach the app (so i do listen the port 3000) and socket.io is working unless this error, but in some cases, the emit call desn't send any arguments so i get undefined.

为了避免此错误,我在这里想念什么?

What am i missing here to avoid this error?

推荐答案

我发现了一些避免此错误的方法:

I have found something to avoid this error:

io.set('transports', ['xhr-polling']);

socket.io现在可以进行AJAX调用了,它的工作确实很慢,但是速度肯定要慢得多,因此,如果有人对这个问题有真正的把握,我还是很感兴趣!

So socket.io does now AJAX calls, it does the job but certainly a way much more slowly, so if someone has the real key to this issue i am still very interested!

这篇关于“响应代码:502"表示“使用带有proxy_pass的socket.io和nginx 1.4.x(稳定)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 12:39