server {
? ? ? ? listen 443 ssl;
? ? ? ? server_name localhost;
? ? ? ? ssl on;
? ? ? ? root html;
? ? ? ? index index.html index.htm;
? ? ? ? ssl_certificate? ******.pem;
? ? ? ? ssl_certificate_key? *******.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 /{
? ? ? ? ? ? proxy_pass? http://localhost:3001;? ? ? ?
? ? ? ? ?}
? ? #? 關(guān)鍵點(diǎn)
? ? ?location /ws {
? ? ? ? ? proxy_pass http://localhost:8181;? ? ? ? ? ? proxy_read_timeout 60s;
? ? ? ? ? proxy_http_version 1.1;
? ? ? ? ? proxy_set_header Upgrade $http_upgrade;
? ? ? ? ? proxy_set_header Connection 'Upgrade';
? ? ? ? }? ?
? ? }
原理解析:
WebSocket協(xié)議的握手和HTTP是兼容的芙盘,它使用HTTP的Upgrade協(xié)議頭將連接從HTTP連接升級到WebSocket連接葡兑。這個(gè)特性使得WebSocket應(yīng)用程序可以很容易地應(yīng)用到現(xiàn)有的基礎(chǔ)設(shè)施
就可以使用https//+域名訪問和使用wss://+域名+/ws訪問了
原文地址:nginx 配置https和wss
參考鏈接:分享下nginx配置HTTPS WSS