ssl - websocket請(qǐng)求nginx監(jiān)聽的端口,出現(xiàn)WebSocket opening handshake was canceled
問題描述
nginx版本是1.10.1
nginx配置tcp轉(zhuǎn)發(fā):
tcp{ upstream ge_ssl { server 127.0.0.1:1234; } map $http_upgrade $connection_upgrade{ default upgrade; ’’ close; }server{ listen 9988; ssl on; ssl_certificate /etc/le/l/abc.com/fullchain.pem; ssl_certificate_key /etc/le/l/abc.com/privkey.pem; ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { proxy_pass http://ge_ssl; proxy_http_version 1.1; #proxy_ssl_session_reuse off; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; } } }
nginx監(jiān)聽端口:443,80,9988
443:ssl證書 80:rewrite 跳轉(zhuǎn)4439988:該端口為了應(yīng)對(duì)網(wǎng)頁的websocket請(qǐng)求,然后將請(qǐng)求轉(zhuǎn)發(fā)給1234端口
瀏覽器:FireFox,Chrome
網(wǎng)頁代碼:
var ws = new WebSocket(’ws://129.136.145.58:9988’); 在FireFox上面,可以通過,Chrome上面,會(huì)出錯(cuò),錯(cuò)誤如下: Mixed Content: The page at ’https://www.abc.com/me’ was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint ’ws://129.136.145.58:9988/’. This request has been blocked; this endpoint must be available over WSS. Uncaught SecurityError: Failed to construct ’WebSocket’: An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.所以網(wǎng)頁代碼改用為var ws = new WebSocket(’wss://129.136.145.58:9988’);這下FireFox和Chrome一起失敗了...錯(cuò)誤如下: WebSocket connection to ’wss://129.136.145.58:9988/’ failed: WebSocket opening handshake was canceled
查了好多資料都不知道為啥,求大神指點(diǎn)一二,感激不盡。。。
問題解答
回答1:https和ws不能混用,用http和wss
