个人技术网站 欢迎关注
最近在做websocket推送日志到前台页面,部署服务器是用nginx转发后无法连接websocket,而且我的nginx还是带https证书的,下面转发的配置可以解决这一问题(仅供参考)
#将/xcloud-api请求转发给http://127.0.0.1:8012处理
location /xcloud-api {
proxy_pass http://127.0.0.1:8012/xcloud-api; #这里的端口记得改成项目对应的哦
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
proxy_set_header Host $host;
proxy_http_version 1.1;
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 Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Origin "";
proxy_redirect off;
}
主要是这三个配置
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Origin "";