这是我nginx的配置
upstream wss {
server 127.0.0.1:2345;
}
server
{
listen 80;
listen 443 ssl;
server_name xxx.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/xxx;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
ssl on;
ssl_certificate xxx.pem;
ssl_certificate_key xxx.key;
ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497 https://$host$request_uri;
location /wss
{
proxy_redirect off;
proxy_pass http://wss;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection Upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 3600s;
}
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
error_page 404 /404.html;
error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-70.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/xxx.conf;
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log off;
access_log /dev/null;
}
access_log /www/wwwlogs/xxx.log;
error_log /www/wwwlogs/xxx.error.log;
}
这是我Workerman的代码
<?php
use Workerman\Worker;
require_once __DIR__ . '/vendor/workerman/workerman/Autoloader.php';
// 证书最好是申请的证书
/*$context = array(
// 更多ssl选项请参考手册 http://php.net/manual/zh/context.ssl.php
'ssl' => array(
// 请使用绝对路径
'local_cert' => 'xxx.pem', // 也可以是crt文件
'local_pk' => 'xxx.key',
'verify_peer' => false,
// 'allow_self_signed' => true, //如果是自签名证书需要开启此选项
)
);*/
// 创建一个Worker监听2345端口,使用websocket协议通讯
$http_worker = new Worker("websocket://0.0.0.0:2345");
$http_worker->count = 1;
//$http_worker->transport = 'ssl';
// 接收到浏览器发送的数据时广播给所有用户
$http_worker->onMessage = function($connection, $data){
$connection->send('hello ' . $data);
};
Worker::runAll();
我用代码workerman就可以使用,但用nginx反向代理就不行
workerman手册说nginx做ssl代理后,workerman就不能设置ssl和证书了,感觉你的是这个问题。
我workerman的ssl这个是注释掉的
<?php
use Workerman\Worker;
require_once __DIR__ . '/vendor/workerman/workerman/Autoloader.php';
// 证书最好是申请的证书
/$context = array(
// 更多ssl选项请参考手册 http://php.net/manual/zh/context.ssl.php
'ssl' => array(
// 请使用绝对路径
'local_cert' => 'xxx.pem', // 也可以是crt文件
'local_pk' => 'xxx.key',
'verify_peer' => false,
// 'allow_self_signed' => true, //如果是自签名证书需要开启此选项
)
);/
// 创建一个Worker监听2345端口,使用websocket协议通讯
$http_worker = new Worker("websocket://0.0.0.0:2345");
$http_worker->count = 1;
//$http_worker->transport = 'ssl';
// 接收到浏览器发送的数据时广播给所有用户
$http_worker->onMessage = function($connection, $data){
$connection->send('hello ' . $data);
};
Worker::runAll();