简体   繁体   中英

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.

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;
}

What are configuration that I need to do in (sudo nano /etc/nginx/sites-available/default) file to make sockets work.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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