您现在的位置是:首页 > Ngxin下配置websocket

Ngxin下配置websocket

默认 2019-09-04 09:23 1493人围观 来源:原创
nginx   wss  
简介一般webscoket服务端都是一个4位数的端口在跑,比如9501,如果是web端对接没什么问题,但是微信小程序等场景下不允许使用特殊端口只允许使用443端口,这个时候出现冲突了,因为网站本身的接口也在443下面。

那么ngxin是支持http和websocket公用443端口的,比如你有一个网站https://jiangruyi.com,同时你需要配置一个wss://jiangruyi.com的websocket接口,可以参考一下配置:

 

    # 代理socket
    location /wss {
        proxy_pass http://127.0.0.1:9508;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header X-Real-IP $remote_addr;
    }
我的博客即将同步至腾讯云开发者社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=3cn0udci9ym88

文章评论