http {
map $http_upgrade $connection_upgrade {
default upgrade ;
‘‘ close ;
}
server{
location /ws/ {
proxy_pass http://192.168.3.1:9000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
然而调试的时候得到了以下的响应
Handshake status 403 None
### closed ###
起初一直以为是后端服务器的问题,经过几番周转,最后发现还是nginx配置的问题,可以在location中添加以下的配置来解决这问题
proxy_set_header Origin ‘‘;
最终的正确配置为
http {
map $http_upgrade $connection_upgrade {
default upgrade ;
‘‘ close ;
}
server{
location /ws/ {
proxy_pass http://192.168.3.1:9000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Origin ‘‘;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}