i'm trying to using Laravel-Echo-Server in my project, in Local there is no error but when i host it to RunCloud the Laravel Echo Server is running but my website cant connect to Laravel Echo Server.. I try to add new custom nginx rule in location.main like laravel echo server doc said but still error
laravel-echo-server.json
{
"authHost": "https://exampledomain.com",
"authEndpoint": "/broadcasting/auth",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": false,
"host": null,
"port": "6001",
"protocol": "https",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "path/server.crt",
"sslKeyPath": "path/server.key",
"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"
}
}
laravel-echo-setup.js
import Echo from 'laravel-echo';
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ":" + window.laravel_echo_port
});
dashboard.blade.php (in ENV i have set LARAVEL_ECHO_PORT=6001)
<script src="//{{ Request::getHost() }}:{{env('LARAVEL_ECHO_PORT')}}/socket.io/socket.io.js"></script>
<script src="{{ url('/js/laravel-echo-setup.js') }}" type="text/javascript"></script>
<script type="text/javascript">
var i = 0;
window.Echo.channel('vehicle-channel')
.listen('.App\\Events\\NewVehicle', function (newVehicle){
i++;
console.log(newVehicle.newVehicle);
});
</script>
RunCloud Custom Nginx for my webapplication
webapp.location.main.laravelecho.conf
#the following would go within the server{} block of your web server config
location /socket.io {
proxy_pass http://localhost:6001; #could be localhost if Echo and NginX are on the same box
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
Here some Picture Laravel Echo Server is Running and My Webapps cant connect to socketio.js
So here I think you need to create a separate file for running laravel-echo-server continuously with help of PM2.
For that, you need to create a file with anyname.config.js
and add this code inside this file
module.exports = {
apps: [
{
name: 'laravel-echo-server',
script: 'laravel-echo-server',
instances: 1, // default 'laravel-echo-server' required 1 instance only to work
exec_mode: 'fork', // default
interpreter: 'node', // default
args: 'start',
error_file: './storage/logs/pm2/pm2.error.log',
out_file: './storage/logs/pm2/pm2.out.log',
pid_file: './storage/logs/pm2/pm2.pid.log',
cwd: "PROJECT_ROOT_DIRECTORY_PATH", // var/www/html/project
}
]
};
After that you need to set following code in laravel-echo-server.json
file on root level of project directory.
{
"authHost": "http://example.com",
"authEndpoint": "/broadcasting/auth",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": false,
"allowOrigin": "",
"allowMethods": "",
"allowHeaders": ""
}
}
That's it. Now you can start your node laravel-echo-server by watch anyname.config.js file with PM2.
To start PM2 Watch list and run the server use sudo pm2 start anyname.config.js --watch
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.