laravel - WebSocket 连接到 'wss://***:6001/socket.io/?EIO=3&transport=websocket' 失败:WebSocket 已关闭
问题描述
我正在使用laravel。我想在 SSL 上连接一个套接字连接。
Echo Version: 1.6.2
Laravel Version: 5.7.28
PHP Version: 7.2.31
NPM Version: 6.14.5
Node Version: 11.15.0
我正在使用 SSL 协议。我从前端收到此错误消息:
WebSocket connection to 'wss://example.com:6001/socket.io/?EIO=3&transport=websocket' failed: WebSocket is closed before the connection is established
这是我的 laravel-echo-server.json
{
"authHost": "https://example.com",
"authEndpoint": "/broadcasting/auth",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "https",
"socketio": {},
"secureOptions": ****,
"sslCertPath": "........",
"sslKeyPath": "........",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": true,
"allowOrigin": "*",
"allowMethods": "GET,POST",
"allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
}
}
还有我的 apache2 配置:
<VirtualHost *.*.*.*:80>
ServerName example.com
ServerAlias mail.example.com www.example.com
DocumentRoot /home/example/public_html
ServerAdmin webmaster@example.com
UseCanonicalName Off
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:6001/$1 [P,L]
ProxyPass /socket.io/ http://localhost:6001/socket.io
ProxyPassReverse /socket.io/ http://localhost:6001/socket.io
## User example # Needed for Cpanel::ApacheConf
<IfModule userdir_module>
<IfModule !mpm_itk.c>
<IfModule !ruid2_module>
<IfModule !mod_passenger.c>
UserDir disabled
UserDir enabled example
</IfModule>
</IfModule>
</IfModule>
</IfModule>
解决方案
推荐阅读
- php - 替换数组中的键,保持顺序不变
- python-3.x - Python子进程docker线程不起作用
- json - 无法从 json 反序列化 chrono::DateTime
- python - 在 python 中使用 json 发送数据的问题(ut8 错误)
- c# - xamarin Interstitia 广告需要点击两次按钮才能显示
- airflow - 安装 dnspython Airflow docker puckel 时出现问题
- maven - pom.xml的Url标签可以在代码中使用吗
- javascript - 如何在 amchart 脚本中传递用户输入和自定义函数创建?
- python - 反转具有多个分配的链表 - 并非所有分配顺序都有效?
- c++ - 矩阵结构的 C++ 重载运算符