設定 https://example.com:9999/socket.io
反向代理到 http://192.168.0.10:9999 的 WebSocket 服務
map $http_upgrade $connection_upgrade { default Upgrade; '' close; } upstream websocket { server 192.168.0.10:9999; } server { listen 9999 ssl; server_name example.com; #ssl ssl_certificate /etc/nginx/ssl/example.com.crt; ssl_certificate_key /etc/nginx/ssl/example.com.key; location /socket.io { proxy_pass http://websocket; #Version 1.1 is recommended for use with keepalive connections proxy_http_version 1.1; #WebSocket proxy_set_header Upgrade $http_upgrade; #WebSocket proxy_set_header Connection $connection_upgrade; #WebSocket proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Cookie $http_cookie; } location = /favicon.ico { log_not_found off; access_log off; } }
參考:
- https://www.nginx.com/blog/websocket-nginx/
Using NGINX as a WebSocket Proxy - https://single9.net/2018/03/nginx-reverse-proxy-server-and-socket-io/
老闆!來一個能支援 Socket.io 的 NGINX Reverse Proxy Server 吧! | Single.9 - https://kknews.cc/code/pn42zoj.html
伺服器nginx下websocket nginx 配置心得分享 - https://github.com/REBELinBLUE/deployer/issues/310
WebSocket connection handshake Error 502 · Issue #310 · REBELinBLUE/deployer · GitHub
沒有留言:
張貼留言