在文件\application\push\command\Workerman.php中,将startGateWay和startBusinessWorker中增加支持SSL证书即可,参考配置:
private function startBusinessWorker()
{
$context = array(
'ssl' => array(
'local_cert' => ROOT_PATH . '/cert/证书PEM.pem',
'local_pk' => ROOT_PATH . '/cert/证书KEY.key',
'verify_peer' => false,
)
);
// bussinessWorker 进程
$worker = new BusinessWorker('', $context);
// worker名称
$worker->name = $this->config['chat']['name'];
// bussinessWorker进程数量
$worker->count = $this->config['chat']['count'];
//设置处理业务的类,此处制定Events的命名空间
$worker->eventHandler = \app\push\controller\Events::class;
// 服务注册地址
$worker->registerAddress = $this->config['channel']['ip'] . ':' . $this->config['channel']['port'];
$worker->transport = 'ssl';
}
private function startGateWay()
{
$context = array(
'ssl' => array(
'local_cert' => ROOT_PATH . '/cert/证书PEM.pem',
'local_pk' => ROOT_PATH . '/cert/证书KEY.key',
'verify_peer' => false,
)
);
$gateway = new Gateway($this->config['chat']['protocol'] . "://" . $this->config['chat']['ip'] . ":" . $this->config['chat']['port'], $context);
$gateway->name = $this->config['chat']['name'];
// gateway进程数
$gateway->count = $this->config['chat']['count'];
$gateway->startPort = 2900;
// 服务注册地址
$gateway->registerAddress = $this->config['channel']['ip'] . ':' . $this->config['channel']['port'];
$gateway->transport = 'ssl';
}
修改前端访问格式为:wss即可。
可自行参考是否使用哦!