nginx socket connector configuration

author: headsen  chen

date:  2019-08-08 18:52:36  

notice: personal original

Nginx supports WebSockets communication by establishing a tunnel between the client and the backend server. To make Nginx may Upgrade from the client request to the backend server, and Connection Upgrade header information must be explicitly set. As follows:
    location /wsapp/ {
        proxy_pass http://wsbackend;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
Once we have completed the above settings, Nginx can handle the WebSocket connection.

Production configuration examples:
[root@beta-aaa01:/usr/local/openresty/nginx/conf/locations]$cat location aaa.bbbb.cn.conf 

    location  / { 
        proxy_pass http://10.0.0.3:8702/;
            proxy_http_version 1.1;
            proxy_redirect off;
            proxy_buffering off;
            proxy_set_header X-NginX-Proxy true;
            proxy_set_header Host $host;
            proxy_set_header Http-Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
    }

 

Guess you like

Origin www.cnblogs.com/kaishirenshi/p/11323111.html