admin管理员组

文章数量:1122826

Im trying to protect a server who use socket.io to handle websocket connections. Howewer, I don't manage to get my nginx reverse proxy working with it.

Requests on web console ( no reverse used ), everything works fine :

Once the reverse is active, socket.io don't work anymore. That's what I got :

I can't connect to the websocket and I don't get any error logs. Here my nginx configuration :

upstream socketIOserver {
    server protectedIP:80;
}

server {
    listen 80;
    listen [::]:80;
    http2 on;
    server_name api.domain;
    
    error_log /var/log/nginx/error.log;
    
    location /socket.io/ {
        proxy_pass http://socketIOserver/socket.io/;

        proxy_buffering off;
        proxy_cache off;
        
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';

        proxy_buffers 8 32k;
        proxy_buffer_size 64k;
        proxy_connect_timeout 7d;
        proxy_send_timeout 7d;
        proxy_read_timeout 7d;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
    }

    location / {
        proxy_pass http://socketIOserver;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;  # This line.
        proxy_set_header Host $host;
    }
    
}

Thanks for your help.

本文标签: websocketSocketio don39t work with nginx reverse proxyStack Overflow