From b2617a7e0435d8aa64bbacbd9f64997474f6833b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=AA=E5=AD=90=E5=B0=8F=E6=96=B0?= Date: Tue, 31 Mar 2020 20:20:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BF=AE=E6=94=B9=E5=89=8D=E5=8F=B0ws?= =?UTF-8?q?=E3=80=81wss=E8=87=AA=E5=8A=A8=E5=88=A4=E6=96=AD)=20style(readm?= =?UTF-8?q?e)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 20 ++++++++++++++++++++ staticweb/js/index.js | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 16d52ea..71702ac 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,23 @@ task进程数可以根据需要多开一些,默认为10
9.另外,部署到香港、韩国、日本等非大陆的服务器的事情就不用我说了吧。推荐使用:www.vultr.com日本服务器
10.如果您也搭建了此服务,我们可以互粉一下友情链接,组合成一个阵营,互粉群:G.widora.cn 互粉群 +####nginx转发ws or wss示例 + ``` + upstream websocket { + server 127.0.0.1:8848; + } + server { + ...//...代表您的nginx其他配置 + + location /wss { + proxy_pass http://websocket; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + } + + } +//配置完成后,修改 style/js/index.js中连接ws部分为: +// __this.ws = new WebSocket("ws" + (ishttps ? "s": "") + "://" + document.domain + "/wss"); //nginx配置ssl做8848转发 +``` + diff --git a/staticweb/js/index.js b/staticweb/js/index.js index d071359..eba9bbd 100644 --- a/staticweb/js/index.js +++ b/staticweb/js/index.js @@ -5,7 +5,9 @@ var webSocketClick = { init:function(){ var __this = this; __this.app_block = $(".app-block"); - __this.ws = new WebSocket("wss://" + document.domain + ":8848"); + var ishttps = 'https:' == document.location.protocol ? true: false; + __this.ws = new WebSocket("ws" + (ishttps ? "s": "") + "://" + document.domain + ":8848"); + // __this.ws = new WebSocket("ws" + (ishttps ? "s": "") + "://" + document.domain + "/wss"); //nginx配置ssl做8848转发 __this.ws.onopen = function(event){ __this.onOpen(event) }