因為網(wǎng)站用的是https所以按文檔方法1配置了
http://wtbis.cn/doc/workerman/faq/secure-websocket-server.html
然后一直連不上...
試過一個端口的,如下:
![
![
服務(wù)端端口 2346 (配置了ssl)
服務(wù)端端口 2347
為啥子會有兩個端口?
客戶端連接的端口 2347
Mixed Content: The page at 'https://527.html' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://ip:2347/'. This request has been blocked; this endpoint must be available over WSS.
(anonymous) @ 527.html:97
Uncaught DOMException: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.
用ws就報這個錯 然后根據(jù)文檔搞了wss = =一開始用的是NGINX配置,不行我才改用方法1的
可以在線測試啊 有很多在線可以ws連接網(wǎng)站的 例如 這個就可以 https://www.qvdv.com/tools/qvdv-websocket.html
先不用wss,使用ws連接是否正常?
別一根筋啊!瀏覽器控制臺console,先測試一下是否是通的
var ws = new WebSocket('wss://127.0.0.1:8988/');
ws.onmessage = function(event) {
console.log('頻道初始化,接收消息: ' + event.data);
};
// 發(fā)送消息
let _content = {
"event": "join_channel",
"content": "拉姆,今天沒去放羊嗎?"
};
ws.send(JSON.stringify(_content));
VM610:11 Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
at <anonymous>:11:4
(anonymous) @ VM610:11
VM610:1 WebSocket connection to 'wss://127.0.0.1:8988/' failed:
VM676:11 Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
VM676:3 頻道初始化,接收消息: {"type":"init","client_id":"7f0000010b540000020d","user":"","message":"ok"}
nginx代理
server {
listen 443 ssl http2;
server_name wss.live.tinywan.cn;
ssl on;
ssl_certificate /home/www/.acme.sh/wss.live.tinywan.cn/wss.live.tinywan.cn.cer;
ssl_certificate_key /home/www/.acme.sh/wss.live.tinywan.cn/wss.live.tinywan.cn.key;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
location /wss
{
proxy_pass http://127.0.0.1:8902;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IP $remote_addr;
}
}
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
目前配置是這樣的!區(qū)別不是很大 0.0