我仅在使用 laravel-echo-server , redis , ssl 的实时服务器上遇到一个奇怪的问题。
错误:
GET https://dev.my_domain.com:6001/socket.io/?EIO=3&transport=polling&t=Ml1g-Fq net::ERR_CONNECTION_TIMED_OUT
下面您可以找到我的配置: laravel-echo-server.json
{
"authHost": "https://dev.my_domain.com",
"authEndpoint": "/broadcasting/auth",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {
"port": "6379",
"host": "127.0.0.1"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "https",
"socketio": {},
"sslCertPath": "/etc/letsencrypt/live/dev.my_domain.com/fullchain.pem",
"sslKeyPath": "/etc/letsencrypt/live/dev.my_domain.com/privkey.pem"
}
Bootstrap.js
import Echo from 'laravel-echo';
window.io = require('socket.io-client');
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
端口6001已启用:
tcp6 0 0 :::6001 :::* LISTEN 10728/laravel-echo-
运行laravel-echo-server启动后
L A R A V E L E C H O S E R V E R
version 1.5.5
⚠ Starting server in DEV mode...
✔ Running at localhost on port 6001
✔ Channels are ready.
✔ Listening for http events...
✔ Listening for redis events...
Server ready!
在没有ssl配置的情况下,它可以在我的本地主机上正常工作。
让我知道是否有人可以解决此问题,
提前感谢大家
答案 0 :(得分:0)
我找到了解决问题的方法。
下面的配置现在看起来还可以:),
首先,您需要更新apache2配置: 启用模块:
a2enmod proxy_wstunnel
更新apache配置
位置:/etc/apache2/sites-available/**your_domain_config**.conf
添加到此处:
SSLEngine on
SSLProxyEngine On
ProxyRequests Off
ProxyPass /socket.io http://dev.DOMAIN.com:6001/socket.io
ProxyPassReverse /socket.io http://dev.DOMAIN.com:6001/socket.io
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* ws://dev.DOMAIN.com:6001%{REQUEST_URI} [P]
重新启动Apache:
systemctl restart apache2
我的laravel-echo-server-json:
{
"authHost": "https://dev.DOMAIN.com",
"authEndpoint": "/broadcasting/auth",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {
"port": "6379",
"host": "127.0.0.1"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "https",
"socketio": {},
"sslCertPath": "/etc/letsencrypt/live/DOMAIN/fullchain.pem",
"sslKeyPath": "/etc/letsencrypt/live/DOMAIN/privkey.pem"
}
更新Bootstrap.js:
import Echo from 'laravel-echo';
window.io = require('socket.io-client');
window.Echo = new Echo({
broadcaster: 'socket.io',
host: { path: '/socket.io' }
});