首页 > 解决方案 > 带有 NGINX 的 Socket.io。无法为套接字工作进行配置

问题描述

我有socket.io的后端,我想用nginx配置socket.io。在 nginx 进行以下配置之后,我可以使除套接字以外的其他路由正常工作,但我的套接字不工作。

server_name yourdomain.com www.yourdomain.com;

location / {
    proxy_pass http://localhost:5000; #whatever port your app runs on
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

我需要在(sudo nano /etc/nginx/sites-available/default)文件中进行哪些配置才能使套接字工作。

标签: javascriptnode.jsnginxsocket.ioconfiguration

解决方案


您是否尝试添加

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

到您的位置配置?

https://www.nginx.com/blog/nginx-nodejs-websockets-socketio


推荐阅读