nginx之代理websocket
nginx代理websocket:
NGINX通过允许一个在客户端和后端服务器之间建立的隧道来支持WebSocket。
为了NGINX发送来至于客户端Upgrade请求到后端服务器,Upgrade和Connection头部必须被设置明确
map $http_upgrade $connection_upgrade { default Upgrade; '' close; } server { server_name kubesphere.www.com; location ~ / { proxy_http_version 1.1; proxy_set_header HOST $host; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://10.1.1.12:30880; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_read_timeout 900s; proxy_buffering off; }
验证websocket服务:
curl --no-buffer -H 'Connection: keep-alive, Upgrade' -H 'Upgrade: websocket' -v -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: websocket' http://192.244.0.43:9103/alive
--------崔帅的拾荒