简体   繁体   English

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

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

I have my backend with socket.io and i want to configure socket.io with nginx. After nginx following configurations, I am able to make my routes other than sockets to work but my sockets are not working.我的后端是 socket.io,我想用 nginx 配置 socket.io。在 nginx 以下配置之后,我可以使 sockets 以外的路由正常工作,但我的 sockets 不工作。

server_name yourdomain.com www.yourdomain.com;服务器名称 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;
}

What are configuration that I need to do in (sudo nano /etc/nginx/sites-available/default) file to make sockets work.我需要在 (sudo nano /etc/nginx/sites-available/default) 文件中做什么配置才能使 sockets 工作。

Did you try adding您是否尝试添加

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

to your location config?到你的位置配置?

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

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

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