The Websocket connection is unstable, disconnecting and reconnecting within 60 seconds

The local test is normal, but the online test is always disconnected after a while...

The https protocol has been added online, so the links on the page must also be ssl

Websocket link address ws://ws.xxx.comchanged fromwss://ws.xxx.com

The initial httpconfiguration is as follows:

server {
    
    
    listen 80;
    server_name ws.xxx.com;

    location / {
    
    
        proxy_pass http://127.0.0.1:8110;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Upgrade $http_upgrade;
        client_max_body_size 1000m;
        proxy_read_timeout 360s;
    }
}

httpsAfter upgrading to sslthe configuration:

server {
    
    
    listen 443 ssl;
    server_name ws.xxx.com;

    ssl_certificate /usr/local/nginx/ws.xxx.com.crt;
    ssl_certificate_key /usr/local/nginx/ws.xxx.com.key;

    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers  on;

    location / {
    
    
        proxy_pass http://127.0.0.1:8110;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Upgrade $http_upgrade;
        client_max_body_size 1000m;
    }
}

sslWhen adding a proxy to Nginx online , there is no settingproxy_read_timeout

The correct approach should be to proxy_read_timeoutconfigure a time greater than Websocketthe heartbeat time

Reference:
Nginx Proxy Configuration
Nginx Reconnection Time

Guess you like

Origin blog.csdn.net/gaofengzks/article/details/120650890