繁体   English   中英

Socket.io 和 NGINX。无法为 sockets 工作进行配置

[英]Socket.io with NGINX. Unable to do configurations for sockets to work

我的后端是 socket.io,我想用 nginx 配置 socket.io。在 nginx 以下配置之后,我可以使 sockets 以外的路由正常工作,但我的 sockets 不工作。

服务器名称 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) 文件中做什么配置才能使 sockets 工作。

您是否尝试添加

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

到你的位置配置?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM