新建代理 填写域名等服务信息,选择支持WebSockets。 创建 SSL 编写nginx配置
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 ;
}
// 消息ws服务器
Router::addServer( 'message' , function ( ) {
Router::get( '/message.io' , 'App\Controller\Web\WebSocketController' , [
'middleware' = > [ \ App\ Middleware\ WsAuthMiddleware::class] , // ws中间件
] ) ;
} ) ;
[
'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 ,
] ,
] ,
wss://wsdev.com/message.io