首先申请号ssl 证书,安装好
服务内建立自己的tcp 服务
然后通过nginx 转发 到自己的进程内
比如下面这样写,等于,wss://xxxxx.com/wss 就转发到了 服务器内的127.0.0.1:2347服务。
这样微信小程序就可以正常使用wss服务了
具体转发可以放在 文件配置或者 伪静态里面
建议放在伪静态里面容易管理
注意下面的配置 是,在400s 以内必须进行一次请求,这里需要使用心跳
location /wss {
proxy_pass http://127.0.0.1:2347;
proxy_read_timeout 400s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IP $remote_addr;
}
这是可以的一直提示 2300 冲突,重启服务后没有问题了
location /ws {
# return 456;
proxy_pass http://127.0.0.1:7100; # 将请求转发到Workerman监听的端口
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
# 其他可能需要的代理设置
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
这是另一种转发,这里把/zhuan/live 转到了 /live 下面
location /zhuan/live/ {
# 去除路径中的 /zhuan 前缀
rewrite ^/zhuan/live/(.*)$ /live/$1 break;
# 代理到后端服务器
proxy_pass http://127.0.0.1:23481;
# 代理相关配置
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}