test: 测试在宝塔服务器上的配置反应
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
|
|
||||||
server {
|
server {
|
||||||
listen 80;
|
# 作为默认站点接管所有 Host(域名/IP)
|
||||||
|
listen 80 default_server;
|
||||||
# listen 443 ssl http2; # Enable HTTP/2
|
# listen 443 ssl http2; # Enable HTTP/2
|
||||||
|
|
||||||
server_name localhost;
|
# 匹配任意域名/IP(Host 不限制)
|
||||||
|
server_name _ localhost 127.0.0.1;
|
||||||
root /var/www/html;
|
root /var/www/html;
|
||||||
index index.php index.html index.htm default.php default.htm default.html;
|
index index.php index.html index.htm default.php default.htm default.html;
|
||||||
|
|
||||||
|
|||||||
@@ -197,7 +197,7 @@
|
|||||||
|
|
||||||
// 设置WebSocket服务器地址
|
// 设置WebSocket服务器地址
|
||||||
const setWebsocketUrl = () => {
|
const setWebsocketUrl = () => {
|
||||||
if (websocketUrl.value.trim() && websocketUrl.value.startsWith('ws://')) {
|
if (websocketUrl.value.trim() && (websocketUrl.value.startsWith('ws://') || websocketUrl.value.startsWith('wss://'))) {
|
||||||
addons.forEach(addon => {
|
addons.forEach(addon => {
|
||||||
addon.fullPath = websocketUrl.value + addon.path;
|
addon.fullPath = websocketUrl.value + addon.path;
|
||||||
addon.status = 'disconnected';
|
addon.status = 'disconnected';
|
||||||
|
|||||||
@@ -64,7 +64,16 @@ use Ratchet\ConnectionInterface;
|
|||||||
use Ratchet\MessageComponentInterface;
|
use Ratchet\MessageComponentInterface;
|
||||||
|
|
||||||
// 配置WebSocket服务器
|
// 配置WebSocket服务器
|
||||||
$httpHost = 'localhost'; // 客户端连接时使用的主机名
|
// Ratchet\App 的 $httpHost 会被用于路由 Host 匹配(默认要求必须等于 ws://<host> 的 host)
|
||||||
|
// 注意:Ratchet\App 构造函数内部会把 $httpHost 传给 FlashPolicy::addAllowedAccess(),
|
||||||
|
// 为空会触发 “Invalid domain”。因此这里必须是一个合法域名/IP(用 localhost 兜底)。
|
||||||
|
// 若希望通过任意 IP/域名访问:不要在构造里用空值;而是在 route(...) 的第4个参数传 '',
|
||||||
|
// 让该路由不限制 Host。
|
||||||
|
$httpHost = getenv('WS_HTTP_HOST');
|
||||||
|
$httpHost = ($httpHost === false) ? 'localhost' : trim((string)$httpHost);
|
||||||
|
if ($httpHost === '') {
|
||||||
|
$httpHost = 'localhost';
|
||||||
|
}
|
||||||
$port = getenv('WS_PORT') ?: 8080; // WebSocket服务器端口
|
$port = getenv('WS_PORT') ?: 8080; // WebSocket服务器端口
|
||||||
$address = '0.0.0.0'; // 监听所有网络接口
|
$address = '0.0.0.0'; // 监听所有网络接口
|
||||||
|
|
||||||
@@ -193,7 +202,8 @@ foreach ($current_addon_names as $addonName) {
|
|||||||
if (class_exists($webSocketClass)) {
|
if (class_exists($webSocketClass)) {
|
||||||
// 注册到/ws/{addonName}路径
|
// 注册到/ws/{addonName}路径
|
||||||
$path = '/ws/' . $addonName;
|
$path = '/ws/' . $addonName;
|
||||||
$ratchetApp->route($path, new $webSocketClass(), array('*'));
|
// 允许任意 Origin,并且不限制 Host(支持通过任意 IP/域名访问)
|
||||||
|
$ratchetApp->route($path, new $webSocketClass(), array('*'), '');
|
||||||
echo "已注册WebSocket控制器:{$webSocketClass} 到路径 {$path}\n";
|
echo "已注册WebSocket控制器:{$webSocketClass} 到路径 {$path}\n";
|
||||||
$registeredAddons[] = $addonName;
|
$registeredAddons[] = $addonName;
|
||||||
} else {
|
} else {
|
||||||
@@ -260,7 +270,8 @@ class DefaultWebSocketController implements MessageComponentInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 注册默认的/ws路径测试控制器
|
// 注册默认的/ws路径测试控制器
|
||||||
$ratchetApp->route('/ws', new DefaultWebSocketController(), array('*'));
|
// 默认测试路径同样不限制 Host
|
||||||
|
$ratchetApp->route('/ws', new DefaultWebSocketController(), array('*'), '');
|
||||||
echo "已注册默认WebSocket测试控制器到路径 /ws\n";
|
echo "已注册默认WebSocket测试控制器到路径 /ws\n";
|
||||||
|
|
||||||
// 缓存WebSocket服务器信息(可选,用于其他服务查询)
|
// 缓存WebSocket服务器信息(可选,用于其他服务查询)
|
||||||
|
|||||||
Reference in New Issue
Block a user