原来网页是http的,现在网站改版成https了,https的网页默认无法使用ws协议的websocket,需要使用wss的。就是websocket ssl。
我的后端使用的是swoole。需要增加配置项ssl_cert_file和ssl_key_file。
$server = new \swoole_websocket_server("0.0.0.0", 9502, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
//配置参数
$server ->set([
'daemonize' => false, //守护进程化。
//配置SSL证书和密钥路径
'ssl_cert_file' => "/root/code/ssl/1_pgres.cn_bundle.crt",
'ssl_key_file' => "/root/code/ssl/2_pgres.cn.key"
]);
发现不好使,swoole安装的时候,需要开启openssl。
pecl install swoole
提示支持openssl的时候,选择yes
enable openssl support? [no] : yes
安装的时候,如果出现错误,有可能是系统里没有安装openssl。
需要安装openssl openssl-devel
yum install openssl openssl-devel
使用php --ri swoole来查看是否安装成功
目前本站已经实现了Websocket SSL