Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add https support #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.settings/org.eclipse.php.core.prefs
.project
workerman/logs
vendor
composer.lock
8 changes: 7 additions & 1 deletion Applications/Todpole/Web/js/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ var Settings = function() {
else
{
// 运行在其它域名上
this.socketServer = 'ws://'+document.domain+':8282';
if("https:" == document.location.protocol){
// wss
this.socketServer = 'wss://'+document.domain+':8283';
}else{
// ws
this.socketServer = 'ws://'+document.domain+':8282';
}
}
}
33 changes: 32 additions & 1 deletion Applications/Todpole/start_gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@

require_once __DIR__ . '/../../vendor/autoload.php';

// 已经申请了证书(pem/crt文件及key文件)放在了/etc/nginx/conf.d/ssl下
// 证书最好是申请的证书
$context = array(
'ssl' => array(
'local_cert' => '/etc/nginx/conf.d/ssl/server.pem', // 也可以是crt文件
'local_pk' => '/etc/nginx/conf.d/ssl/server.key',
'verify_peer' => false,
),
);

// ws
// gateway 进程
$gateway = new Gateway("Websocket://0.0.0.0:8282");
// gateway名称,status方便查看
$gateway->name = 'TodpoleGateway';
$gateway->name = 'TodpoleGatewayWs';
// gateway进程数
$gateway->count = 4;
// 本机ip,分布式部署时使用内网ip
Expand All @@ -37,6 +48,26 @@
// 服务注册地址
$gateway->registerAddress = '127.0.0.1:1237';

// wss
// gateway 进程
$gateway_wss = new Gateway("Websocket://0.0.0.0:8283", $context);
// 设置transport开启ssl,websocket+ssl即wss
$gateway_wss->transport = 'ssl';
// gateway名称,status方便查看
$gateway_wss->name = 'TodpoleGatewayWss';
// gateway进程数
$gateway_wss->count = 4;
// 本机ip,分布式部署时使用内网ip
$gateway_wss->lanIp = '127.0.0.1';
// 内部通讯起始端口,假如$gateway_wss->count=4,起始端口为3700
// 则一般会使用3701 3702 3703 3704 4个端口作为内部通讯端口
$gateway_wss->startPort = 3700;
// 心跳间隔
$gateway_wss->pingInterval = 10;
// 心跳数据
$gateway_wss->pingData = '{"type":"ping"}';
// 服务注册地址
$gateway_wss->registerAddress = '127.0.0.1:1237';

/*
// 当客户端连接上来时,设置连接的onWebSocketConnect,即在websocket握手时的回调
Expand Down
26 changes: 26 additions & 0 deletions Applications/Todpole/start_web.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,39 @@

require_once __DIR__ . '/../../vendor/autoload.php';

// 已经申请了证书(pem/crt文件及key文件)放在了/etc/nginx/conf.d/ssl下
// 证书最好是申请的证书
$context = array(
'ssl' => array(
'local_cert' => '/etc/nginx/conf.d/ssl/server.pem', // 也可以是crt文件
'local_pk' => '/etc/nginx/conf.d/ssl/server.key',
'verify_peer' => false,
),
);

// HTTP
// WebServer
$web = new WebServer("http://0.0.0.0:8383");
// WebServer名称
$web->name = 'TodpoleWebserverHttp';
// WebServer数量
$web->count = 2;
// 设置站点根目录
$web->addRoot('www.your_domain.com', __DIR__.'/Web');

// HTTPS
// WebServer
// https默认是用443端口,需要root运行,这里设置为8443端口,不需要root运行
$web_https = new WebServer("https://0.0.0.0:8443", $context);
// WebServer名称
$web_https->name = 'TodpoleWebserverHttps';
// WebServer数量
$web_https->count = 2;
// 设置transport开启ssl,变成http+SSL即https
$web_https->transport = 'ssl';
// 设置站点根目录
$web_https->addRoot('www.your_domain.com', __DIR__ . '/Web');


// 如果不是在根目录启动,则运行runAll方法
if(!defined('GLOBAL_START'))
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ workerman-todpole

2、运行composer install 安装

3、linux系统命令行进入目录运行 php start.php start -d。windows系统启动方法为双击start_for_win.bat
3、根据自己的实际情况修改Applications/Todpole/start_web.php中ssl证书的路径、域名或端口等

4、浏览器访问地址 http://ip:8383 (ip为服务器ip)如图:(如果无法打开页面请尝试关闭服务器防火墙)
4、linux系统命令行进入目录运行 php start.php start -d。windows系统启动方法为双击start_for_win.bat

5、浏览器访问地址 http://ip:8383 (ip为服务器ip)如图:(如果无法打开页面请尝试关闭服务器防火墙)

## 虚拟空间(静态空间、php、jsp、asp等)安装部署
虚拟空间安装请使用这个包 [网页空间版本](https://github.com/walkor/workerman-todpole-web)
Expand Down