通过nginx反向代理实现https网站连接ws服务
在Nginx配置文件中增加以下内容:
location /websocket { proxy_pass http://127.0.0.1:1234; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header Access-Control-Allow-Origin "*"; }
可以实现对"/websocket"这个路径的反向代理
1234是你的ws服务端口号,/websocket可以改为任何你需要的路径。
前端连接:
ws = new WebSocket("wss://testdomain.com/websocket");
使用你的域名+你配置的代理路径如“/websocket”,就可以连接到服务了。
    欢迎转载,转载时请注明来源。

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号