Nginx websocket代理
首先在http域配置
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
然后在server域增加匹配条件(之前是放 location / {} 下面,发现所有的代理地址都会访问消息服务的地址)
location ^~/websocket {
rewrite /websocket(.*)$ /$1 break;#去掉地址上加的websocket
proxy_pass http://ip:port;#消息服务的ip端口
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Origin "";
}
为了解决上面的问题,在访问消息服务地址的时候,在地址后面拼了个websocket,在Nginx代理在时候把websocket去掉
`ws://${window.location.hostname}:${window.location.port}/websocket `
然后重启Nginx就可以了
浙公网安备 33010602011771号