15 - nginx websocket

 

 

 


Using NGINX as a WebSocket Proxy

 

/etc/nginx/nginx.conf

http {

    # Websocket Setting
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }
    upstream websocket {
        server 127.0.0.1:8888;
    }
 
    server {
        listen 8443;
        
        # Websocket Setting
        location / {
        
            proxy_connect_timeout 6s;
            proxy_send_timeout 1d;
            proxy_read_timeout 1d;
            
            proxy_pass http://websocket;
            
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
    }
}

Checking

watch -n 1 'netstat -ntp | grep -e 8888 | grep -e php | wc -l'