Hyperf 在 NginxProxyManager 如何配置 websocket?

  • 新建代理 填写域名等服务信息,选择支持WebSockets。
  • 创建 SSL
  • 编写nginx配置
bash 复制代码
location /message.io{
    proxy_pass http://<你的ip>:<对应端口号>;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Port $server_port;
}
  • hyperf配置
  • routes.php
bash 复制代码
// 消息ws服务器
 Router::addServer('message', function () {
     Router::get('/message.io', 'App\Controller\Web\WebSocketController', [
         'middleware' => [\App\Middleware\WsAuthMiddleware::class], // ws中间件
     ]);
 });
  • server.php配置
bash 复制代码
 [
            'name' => 'message',
            'type' => Server::SERVER_WEBSOCKET,
            'host' => '0.0.0.0',
            'port' => 9502,
            'sock_type' => SWOOLE_SOCK_TCP,
            'callbacks' => [
                Event::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'],
                Event::ON_MESSAGE => [Hyperf\WebSocketServer\Server::class, 'onMessage'],
                Event::ON_CLOSE => [Hyperf\WebSocketServer\Server::class, 'onClose'],
            ],
            'settings' => [
                // 心跳检测
                'heartbeat_idle_time' => 60,
                'heartbeat_check_interval' => 30,
            ],
        ],
  • 访问路径
bash 复制代码
wss://wsdev.com/message.io
相关推荐
j_linlian14 分钟前
Mac OS ssh 连接提示 Permission denied (publickey)
运维·ssh
大卫的纯爱战士16 分钟前
多线程网络实战之仿qq群聊的服务器和客户端
运维·服务器
Mac@分享吧16 分钟前
PhpStorm 2024 for Mac PHP集成开发工具
ide·macos·php·phpstorm·php语言
网络研究院19 分钟前
Rejetto HFS 服务器存在严重漏洞受到攻击
运维·服务器·安全·黑客·漏洞·警告·hfs
jcLee9544 分钟前
运维系列.Nginx中使用HTTP压缩功能
运维·nginx·http
coisini.cn1 小时前
基于CentOS Stream 9平台搭建RabbitMQ3.13.4以及开机自启
linux·运维·服务器·rabbitmq·centos stream 9
林叔聊渠道分销1 小时前
从0到1构建渠道运营体系:实战案例与策略指南
大数据·运维·人工智能·产品运营·流量运营·渠道运营
程序猿阿伟2 小时前
随着云计算和容器技术的广泛应用,如何在这些环境中有效地运用 Shell 进行自动化部署和管理?
运维·自动化·云计算
Tassel_YUE4 小时前
iptables配置实现NAT(随手记)
linux·运维·服务器·网络·iptables
five-five4 小时前
一文全解Nginx
运维·nginx