Nginx WebSocket代理
官方文档
添加配置
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";示例
upstream ws-prod {
server 192.168.1.1:9090;
}
server {
listen 8081;
charset utf-8;
location / {
# 向后端服务器传递自定义的请求头信息
# proxy_set_header Host $host;
proxy_set_header Host '192.168.1.1:9090';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://ws-prod;
# WebSocket 配置
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# 日志配置
access_log /var/log/nginx/ws-prod_access.log main;
error_log /var/log/nginx/ws-prod_error.log;
}