码迷,mamicode.com
首页 > Web开发 > 详细

nginx配置支持https和wss(websocket)协议

时间:2017-11-07 17:53:49      阅读:1695      评论:0      收藏:0      [点我收藏+]

标签:listen   web   turn   chat   proxy   site   blog   upgrade   inter   

server {
        listen 80;
        listen 443 ssl http2;
        server_name lyz810.com;
 
        root /website/lyz810-main;
 
        ssl_certificate     certificate/lyz810.com.crt;
        ssl_certificate_key certificate/lyz810.com.key;
 
        location /websocket/ {
                internal;
 
                if ( $http_sec_websocket_protocol = "" ) {
                        return 400;
                }
                proxy_pass http://127.0.0.1:$arg_port;
                proxy_http_version 1.1;
                proxy_set_header X-Client-IP $remote_addr;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_read_timeout 300s;
        }
        location /chatRoom {
                rewrite .* /websocket/?port=8100;
        }
        location /chatRobot {
                rewrite .* /websocket/?port=8101;
        }
}

服务器内部起了2个websocket服务,分别监听8100、8101端口nginx根据访问不同的location,选择代理到那个ws服务商

/websocket/是个内部location,直接访问会报错

 

 

参考链接:

http://www.cnblogs.com/weidiao/p/7389744.html

http://www.cnblogs.com/mzsg/p/5623494.html

nginx配置支持https和wss(websocket)协议

标签:listen   web   turn   chat   proxy   site   blog   upgrade   inter   

原文地址:http://www.cnblogs.com/hopelooking/p/7799517.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!