Finalmente capito.
Sebbene il mio sito Web debba ancora supportare un SSL, la soluzione è ottenere Apache per reindirizzare /socket.io a https://localhost:6001/socket.io già configurato per redis . Quindi usa 2.2.3 versione di socket io .
Quindi il mio laravel-echo-server.json non è configurato per SSL.
Ecco il mio laravel-echo-server.json :
{
"authHost": "https://domainName.com",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "xxxxxxx",
"key": "xxxxxxxxxxx"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": false,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"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"
}
}
Come utilizzo laravel-echo-server.json:
import Echo from "laravel-echo";
window.io = require('socket.io-client');
// Have this in case you stop running your laravel echo server
if (typeof io !== 'undefined') {
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname,
});
}
E la mia configurazione apaxhe all'interno del mio virtualhost SSL per il mio dominio:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:6001/$1 [P,L]
ProxyPass /socket.io https://localhost:6001/socket.io
ProxyPassReverse /socket.io https://localhost:6001/socket.io
Inoltre richiederebbe un process manager di Node js per mantenere il laravel-echo-server in esecuzione. Quindi ho creato echo-server.json e inserito il seguente codice.
{
"name": "apps",
"script": "laravel-echo-server",
"args": "start"
}
Successivamente, installo pm2 Process Manager. npm install pm2 -g e ho avviato il mio servizio pm2 start echo-server.json --name="apps" .
Infine uso pm2 list per visualizzare tutti i miei servizi e pm2 startup per mantenere attivi i miei servizi.