webtcp 升级为WSS协议
本文地址:http://tongxinmao.com/Article/Detail/id/290
worker gw 升级到最高版本版本不小于3.3.7, 方便小程序使用
增加已下配置启用WSS
// 证书最好是申请的证书
$context = array(
'ssl' => array(
// 请使用绝对路径
'local_cert' => '磁盘路径/server.pem', // 也可以是crt文件
'local_pk' => '磁盘路径/server.key',
'verify_peer' => false,
)
);
// 这里设置的是websocket协议(端口任意,但是需要保证没被其它程序占用)
$worker = new Worker('websocket://0.0.0.0:4431', $context);
// 设置transport开启ssl,websocket+ssl即wss
$worker->transport = 'ssl';
启动后出现Waring: Events::onMessage is not callable 不能收发信息
原因 2016-04-20 GatewayWorker2.0.4版本发布
为避免和Event扩展冲突,原Event.php更名为Events.php,类名也同步改为Events
Events.php中支持设置BusinessWorker进程的onWorkerStart、onWorkerStop回调,
解决方案:
http://wenda.workerman.net/?/question/918
// 需要将eventHandler的默认值Events修改成Event就可以了
$worker->eventHandler = 'Event';
=======================
小程序只能使用443端口,改为反代:
#
# HTTPS server configuration
#
upstream websocket {
server 127.0.0.1:7778;# 远程websocket服务器地址
}
upstream txm{
server tongxinmao.com:80;# 远程http接口
}
server {
# listen 443 ssl default_server;
listen 443 ssl;
server_name tongxinmao.com;
root /usr/share/nginx/html;
#
ssl on;
ssl_certificate /home/ftp/t/txm/1_tongxinmao.com_bundle.crt;
ssl_certificate_key /home/ftp/t/txm/2_tongxinmao.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 20m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
location / {
proxy_pass http://txm;#代理到原有的http的地址去
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Access-Control-Allow-Origin *;#跨域访问设置
}
location /webtcp {
proxy_pass http://websocket;#代理到上面的地址去
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
}
上一篇:PC/服务器外部看门狗设计
下一篇:nginx反向代理HTTPS WSS