Nginx 转发wss 到ws

发布于 2017-07-06  711 次阅读


项目使用https协议,应为一些需求,需要用到一个ws协议的api,但是https下不允许使用ws协议,所以使用 nginx 把一个wss转发该该ws上

 'wss://xiaobai.mxpeng.xyz/tts.do'

 转发到

 'ws://h5.xf-yun.com/tts.do'
server {
    listen       443;
    server_name  xiaobai.mxpeng.xyz

    root         html;

    ssl on;
    ssl_certificate   ../cert/214151690540946.pem;
    ssl_certificate_key  ../cert/214151690540946.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;


    # websocket转发
    location /tts.do {
        proxy_pass   http://h5.xf-yun.com/tts.do;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

使用nginx解决一台服务器中ws协议与wss协议共存问题

Nginx担当WebSockets代理

nginx转发websocket配置


梦想还是要有的,万一实现了呢