beego 框架搭建websocket聊天室,本地是80端口測(cè)試,沒(méi)有考慮線(xiàn)上https情況,當(dāng)部署到線(xiàn)上機(jī)器,發(fā)現(xiàn)https下websocket連接不上,需要進(jìn)行修改,故進(jìn)行記錄,希望遇到的同學(xué),可以少踩坑
js websocket連接方法
function connect() { ws = new WebSocket("wss://"+document.location.host+"/ws"); ws.onopen = onopen; ws.onmessage = onmessage; ws.onclose = function() { console.log("連接關(guān)閉,定時(shí)重連"); connect(); }; ws.onerror = function() { console.log("出現(xiàn)錯(cuò)誤"); }; }nginx配置websocket支持
location /ws { PRoxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_redirect off; proxy_pass http://127.0.0.1:自己的端口/ws; }最終效果如圖

新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注