//nginx配置wss访问方式 map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream websocket { server ip:port; #demo服务的ip和端口 } server { listen 443; server_name xxxx.com; ssl on; ssl_certificate /xx/xx/cert.crt; ssl_certificate_key /xx/xx/cert.key; ssl_session_timeout 5m; ssl_session_cache shared:SSL:50m; ssl_protocols TLSV1.1 TLSV1.2 SSLv2 SSLv3; ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; ssl_prefer_server_ciphers on; # wss协议转发前端页面里面要访问的链接 # 前端访问:wss://domain/demo/apiDataWebSocket location /demo/apiDataWebSocket { proxy_pass http://websocket;#代理到上面的地址去 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } }
参考:
https://www.colabug.com/229850.html
http://nginx.org/en/docs/http/websocket.html