Laravel echo server keeps returning failed status on my server
Code
laravel-echo-server.json
{
"authHost": "http://example.com",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "311dr094tf98745ce",
"key": "fa43bffb3rth63f5ac9c386916ae28e6"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": false,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": true,
"allowOrigin": "http://localhost:80",
"allowMethods": "GET, POST",
"allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
}
}
echo-pm2.json
{
"name": "echo",
"script": "laravel-echo-server.json",
"args": "start"
}
then i run pm2 start echo-pm2.json and status is online but when i visit my web page i keep getting
GET https://www.example.com:6001/socket.io/?EIO=3&transport=polling&t=NA2SNHk net::ERR_TIMED_OUT
Any idea?
"authHost": "http://example.com"
I have this set to the url of my localhost, not sure if it helps you
Solved
The problem was my url was set to https (GET https://www.example.com) while my actual address is running on http (GET http://www.example.com)
so that extra S... :)
Related
I have an issue with my WebSocket setup with Laravel and Apache (cPanel installed apache for me).
I'm using a reverse proxy to proxy requests from MY_DOMAIN/socket.io/ to localhost:6001/socket.io and I'm using mod_proxy_wstunnel too.
It was Ok and was running till yesterday and suddenly, it stopped working! Now I'm getting 301 status and nothing else!
I'll share my ws.conf file, my echo server configuration, and, my client-side code with you right below:
ws.conf
ProxyRequests off
ProxyVia on
RewriteEngine On
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule /(.*) ws://localhost:6001/$1 [P,L]
<Location /ws/>
ProxyPass http://localhost:6001/socket.io
ProxyPassReverse http://localhost:6001/socket.io
Order allow,deny
Allow from all
</Location>
laravel-echo-server.json
{
"authHost": "https://MY_DOMAIN",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "e6c23c397d39255d",
"key": "feb9d433ee789dsc14a536d9l33575a01"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": false,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": false,
"allowOrigin": "",
"allowMethods": "",
"allowHeaders": ""
}
}
client-side code:
import Echo from 'laravel-echo';
if(window.Laravel){
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.Laravel.wsurl, // (I'm setting it in blade)
disableStats: true,
path: '/ws/',
enabledTransports: ['ws'],
transports: ['websocket', 'polling', 'flashsocket'],
csrfToken: window.Laravel.csrfToken
});
}
I have to add, server resources are something like this:
RAM: 64GB (used: 7GB and the rest of it is free)
CPU: AMD5-3600
H.D.D: 240 GB (used: 10GB)
I'll be appreciated any response. :)
I have this weird issue I can't fix with authenticating private channels. I am using Laravel 8, NuxtJS (SPA app), Redis, and separate Docker containers for everything.
When I am trying to listen in my SPA NuxtJs app for the private channel I get the following error:
42["subscription_error","private-robert-test-1",0]
I assume this is because of my echo confing in nuxt.config.js:
echo: {
broadcaster: 'socket.io',
host: 'http://publisher-local.co.uk:8080',
// authModule: true,
// disconnectOnLogout: true,
// token: this.token
},
Then the call looks like this(in the ws tab in my browser):
42["subscribe",{"channel":"private-robert-test-1","auth":{"headers":{}}}]
I assume it should have something in the auth object. So I followed the documentation of NuxtJS Laravel Echo Server package and tried to set authModule to true. As soon as I do that I get this weird error:
Now I imagine that if it worked then auth module would simply add a token to the subscription message I showed before (the one with an empty auth key).
In Laravel I have already done this Broadcast::routes(['middleware' => ['auth:api']]); in the BroadcastServiceProvider.
Although I don't think I am even getting there.
This is my Laravel echo server config file.
{
"apiOriginAllow": {},
"authEndpoint": "/broadcasting/auth",
"authHost": "http://publisher-local.co.uk:8080/api/v1",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {
"host": "redis",
"port": "6379",
"keyPrefix": "",
"options": {
"db": "0"
}
},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
},
"publishPresence": true
},
"devMode": false,
"host": null,
"port": 6001,
"protocol": "http",
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"socketio": {},
"subscribers": {"http": true, "redis": true}
}
Public channels on the other hand work just fine.
What am I missing here? Thank you in advance.
EDIT:
I have also tried creating a plugin for echo where I could populate information I need myself and it looks like this:
export default function ({ $echo, $auth}) {
console.log($echo.connector.options.auth)
let authData = {
headers: {
Authorization: $auth.strategy.token.get(),
Accept: 'application/json',
"X-Requested-With": 'XMLHttpRequest'
},
};
$echo.connector.options.auth = authData;
$echo.options.auth = authData;
}
So I do have the token now and other headers I can see them in the WS tab but it does not make any difference.
Probably not relevant anymore.. But if so..
You should update your version of laravel echo to v2* => https://github.com/nuxt-community/laravel-echo-module/releases/tag/v2.0.0-alpha.5
I know and I have seen this question
Getting ERR_CONNECTION_TIMED_OUT Laravel echo server
But I tried the solution in comment but it doesn't work.
I have my Laravel-echo-server.json
{
"authHost": "https://mysite.it",
"authEndpoint": "/broadcasting/auth",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {
"host":"0.0.0.0",
"port":"6379",
"password": "mypwd"
},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "https",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "path_cert" ,
"sslKeyPath": "path_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-IdOrigin, Content-Type, X-A uth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-IdOri gin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF -TOKEN, X-Socket-Id"
}
}
And I have in my bootstrapjs the connection with Frontend:
import Vue from 'vue'
import Echo from 'laravel-echo'
window.io = require('socket.io-client')
export var echo_instance = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001',
auth: {
headers: {
'Authorization': "Bearer " + localStorage.getItem('token')
}
}
})
Vue.prototype.$echo = echo_instance
export default Vue
I have check if the port was closed but with netstat -an I can see:
tcp6 0 0 :::6001 :::* LISTEN
But when I try to launch my app i receive:
app.js:569 GET
https://mysite.it:6001/socket.io/?EIO=3&transport=polling&t=NKoWZoK
net::ERR_CONNECTION_TIMED_OUT
How can I use the laravel echo with https protocol?
this might be because you have the wrong access token(dynamically added). why don't you try using a static access token first (copy the access token and paste it instead of localStorage.getItem('token')) for the user and see if it works.
Also try putting the following in laravel-echo-server.json file
"allowOrigin": "http://mysite.it:80"
And, see if APP_URL is different in .env file
If I manually run laravel-echo-server - it works fine. But I can't run laravel-echo-server using supervisor: i'm getting error on frontend
GET http://example.com:6001/socket.io/EIO=3&transport=polling&t=MO25vx0net::ERR_CONNECTION_TIMED_OUT
echoserver.log has been created but always empty
I've tried to restart and update supervisor, using sudo
/etc/supervisord.conf:
[program:echo-server]
command=/usr/bin/laravel-echo-server start
dierctory=/var/www/www-root/data/www/example.com
autostart=true
user=root
autorestart=true
stdout_logfile=/var/www/www-root/data/www/example.com/storage/logs/echoserver.log
laravel-echo-server.json:
{
"authHost": "http://example.com",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "fe0ee01ccace98c",
"key": "1138421388769fdbbf88293eb329c16a"
}
],
"database": "redis",
"databaseConfig": {
"redis": {
"port": "6379",
"host": "localhost"
},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": false,
"allowOrigin": "",
"allowMethods": "",
"allowHeaders": ""
}
}
The problem solved by replacing this
command=/usr/bin/laravel-echo-server start
to this
command=/usr/bin/laravel-echo-server start --dir=/var/www/www-root/data/www/example.com
You have a typo in your configuration for directory.
dierctory=/var/www/www-root/data/www/example.com
^^^
# It should be:
directory=/var/www/www-root/data/www/example.com`
I'm using laravel-echo-server along with Redis and vuejs to broadcast events through websockets in Laravel 5.5. with public channels it is working fine and events get broadcasted to client-side correctly. But when I change it to private channel I face problem of authentication even if the callback function inside channel.php file just return true and does not contain any logic for authentication.
I'm using Sentinel authentication package and I don't know if this is the problem. But as I said, when just returning 'true' the problem of authentication still there.
When I check laravel-echo-server I see that there is a error message that says "could not be authenticated, got http code 419".
I read that there are some guys face same issue and what they got is maybe a csrf-token issue or private channel works only with the integrated auth package...etc.
I have included the csrf-token header inside window.Echo config but no result.
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001',
auth: {
headers: {
'X-CSRF-TOKEN': $('meta[name=csrf-token]).attr(content)
}
}
});
routes/channel.php
<?php
Broadcast::channel('adminNotify', function() {
return true;
});
What I did actually in order to make the admin which has the id of 1 able to receive the event is this:
<?php
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
Broadcast::channel('adminNotify', function () {
return (int) Sentinel::check()->id === 1;
});
App\Events\NotifyAdminEvent
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use App\Ad;
use Sentinel;
class NotifyAdminEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $ad;
public function __construct(Ad $ad)
{
$this->ad = $ad;
}
/**
* Get the channels the event should broadcast on.
*
* #return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('adminNotify');
}
}
app.js
require('./bootstrap');
window.Vue = require('vue');
import Echo from 'laravel-echo';
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
laravel-echo-server.json
{
"authHost": "http://192.168.10.11",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "64fe4c095b0ffb30",
"key": "9e2bf37f9b3c8c88c3c5f5e207754f1d"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"apiOriginAllow": {
"allowCors": false,
"allowOrigin": "",
"allowMethods": "",
"allowHeaders": ""
}
}
Laravel log does not log anything so I find it difficult to know what's going on and solve the problem.
I have figured out what happened. The problem was in laravel-echo-server.json file and exactly in the first line "authHost" where instead of putting the ip I had to put the domaine name.
{
"authHost": "http://webdev-app.test",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "64fe4c095b0ffb30",
"key": "9e2bf37f9b3c8c88c3c5f5e207754f1d"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"apiOriginAllow": {
"allowCors": false,
"allowOrigin": "",
"allowMethods": "",
"allowHeaders": ""
}
}