最小 nginx WebSocket 反向代理示例
如果你有类似这样的 nginx 配置子句
location_example.conf
location /app/ {
proxy_pass http://app-server;
}你可以通过在 location { ... } 内添加这些子句来轻松地使其也反向代理 Websocket 连接:
nginx_websocket_snippet.conf
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";完整示例:
nginx_websocket_example.conf
location /app/ {
proxy_pass http://app-server;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}Check out similar posts by category:
Nginx
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow