https证书 websocket配置

2019年12月05日 阅读数:29
这篇文章主要向大家介绍https证书 websocket配置,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

1 经过阿里云申请https证书
图片描述nginx

2 免费证书
图片描述web

3 几分钟后审核经过,将证书部署到服务器上:
图片描述服务器

4 nginx配置websocket

upstream wowcp{
        server 127.0.0.1:9511;
}
upstream wscp{
        server 127.0.0.1:9513;
}
server {
        listen 443;
        server_name wow.0571sd.com;
        ssl on;
        ssl_certificate   cert/cert-1542189031524_wow.0571sd.com.crt;
        ssl_certificate_key  cert/cert-1542189031524_wow.0571sd.com.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;
        location /ws {  #websocket配置
            proxy_pass http://wscp;
            proxy_http_version 1.1;
            proxy_connect_timeout 4s;
            proxy_read_timeout 120s;
            proxy_send_timeout 10s;  
            proxy_set_header Upgrade $http_upgrade;  
            proxy_set_header Connection "Upgrade";
        }
        location / {
            proxy_pass http://wowcp;
        }    
}

5 重启nginx
6 客户端链接websocket地址如:
'wss://wow.0571sd.com/ws?ct=caipiao'session