nginx代理wss

小编的项目后台程序使用 nginx 做 https 代理到 http 导致原来写的 ws  无法正常使用,不得已改为 wss

其实操作很简单,不废话直接上代码

配置 nginx 即可

#升级到 wss
map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

#websocket 代理 (页面请求 wss://)
location /websocket {
     proxy_pass http://127.0.0.1:23001/websocket; #转接路径后台 ws 路径(换成 http )         
     ws://127.0.0.1:23001/websocket (如果是 https 则是转发到 wss)
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";
}

 完成以上配置即可

posted @ 2018-10-17 11:08  chbyiming  阅读(3080)  评论(0)    收藏  举报