banner
Jul 27, 2022
121 Views

Config websocket khi dùng nginx làm proxy

Written by
banner

Giả sử muốn connect websocket vào localhost:8000/wss qua nginx làm proxy

Thêm vào block http của /etc/nginx/nginx.conf

 map $http_upgrade $connection_upgrade{
            default upgrade;
            `` close;
    }



        upstream sshservers {
                server localhost:8000;
        }

Thêm vào block server của /etc/nginx/sites-enables/<config-file>

 location /wss {
                proxy_pass http://sshservers/wss;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";
        }

systemctl restart nginx

Article Tags:
· · ·
Article Categories:
config
banner

Leave a Reply

Your email address will not be published. Required fields are marked *