nginx配置支持https和wss(websocket)協議


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM