I followed the documentation provided, and it seems that the server isn't accepting the connection:
(failed)
net::ERR_CONNECTION_CLOSED
I am using Laravel Horizon, and it appears to be running fine.
If I manually use the redis-cli command to access the server, and
apply the 'ping' command, I get a 'pong' response.
Server appears to be up and running after applying the laravel-echo-server start command:
L A R A V E L E C H O S E R V E R
version 1.3.6
⚠ Starting server in DEV mode...
✔ Running at localhost on port 6001
✔ Channels are ready.
✔ Listening for http events...
✔ Listening for redis events...
Server ready!
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',
});
.env:
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=redis
REDIS_HOST=localhost
REDIS_PASSWORD=null
REDIS_PORT=6379
laravel-echo-server.json
{
"authHost": "http://dialfy.local",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "dd4d563e7e81f442",
"key": "1627b6fd226c7f3c866ca209f78779b6"
}
],
"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": ""
}
}
Any idea on what the issue may be, or where I could start looking? I imagine it is a configuration issue, but I can't seem to put my finger on it.
For anyone else who runs into a similar problem: the reason was because my app was running on https locally, and I did not configure laravel-echo-server to do the same.
Related
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 can't find a solution for more than a week. Everything works fine on the dev server, but not on production. I have no strength, I appeal to you, colleagues :)
I'm using Laravel-echo-server on Socket.io using CloudFlare. When trying to connect, I get an error:
WebSocketError: Unexpected status code received (502 Bad Gateway)
Ubuntu 16.04.7 LTS, Laravel Echo Server: 1.6.1, NodeJs: v12.19.0
laravel-echo-server.json:
{
"authHost": "http://localhost",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "...",
"key": "..."
}
],
"database": "redis",
"databaseConfig": {
"redis": {
"password": "...",
"port": "...",
"db": 0
},
"sqlite": {}
},
"devMode": true,
"host": "",
"port": "6001",
"protocol": "http",
"socketio": {
"transports": ["websocket", "polling"]
},
"secureOptions": 67108864,
"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"
}
}
Nginx host:
server {
listen 8443 ssl;
server_name domain.tld;
ssl_certificate /etc/nginx/ssl/my.crt;
ssl_certificate_key /etc/nginx/ssl/my.key;
error_log /var/log/nginx/domain.tld/ws.log info;
location /ws {
proxy_pass http://127.0.0.1:6001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
After start EchoServer i see:
L A R A V E L E C H O S E R V E R
version 1.6.1
⚠ Starting server in DEV mode...
✔ Running at localhost on port 6001
✔ Channels are ready.
✔ Listening for http events...
✔ Listening for redis events...
Server ready!
Ok, next:
$ curl 127.0.0.1:6001
> OK
Next:
websocat wss://domain.tld:8443/ws
And I get the error:
websocat: WebSocketError: Received unexpected status code (502 Bad Gateway)
Laravel echo server is running, I can see its events. Tried changing the host in laravel-echo-server.json (127.0.0.1, localhost, null, 0.0.0.0), in nginx proxy to localhost, 127.0.0.1 - nothing helps. I tried to add upstreams in nginx host, it doesn't help.
This information also did not help: https://github.com/tlaverdure/laravel-echo-server/issues/273
Please, help :)
I don't know what the problem is, but I found a solution.
I've updated a lot: updated Nginx to 1.19.1, possibly installed some additional modules. Installed npm not globally, but locally.
And it worked ...
Attention: this only works if you write location /socket.io.
That was not the point for sure: "authHost": "http://localhost"
I assume this is your issue.
{
"authHost": "http://localhost" // This should be your domain name
}
I need to host a laravel application that utilizes laravel-echo-server over a HTTPS server.
I want to use Apache's reverse proxy to redirect my /socket.io url polls to 127.0.0.1 on port 6001 which is where laravel-echo-server is running on within the same domain url.
For example over https://example.com when my laravel-echo-server sends url polls to https://example.com/socket.io apache should redirect it to http://127.0.0.1:6001 within that same domain.
NOTICE
I'm not hosting my laravel app at the root directory but in a subdirectory within my cpanel.
My server is a VPS and I am hosting from a sub domain host that runs on a separate IP address from that of the main server host.
Let's say my main host is host.mydomain.com with a unique IP address pointing to the /home/... directory. This runs on http
I now have a domestic.mydomain.com with a unique IP address pointing to the /home/domestic/... directory and this is where I'm hosting my laravel app from. This runs on https.
But my cpanel login is from the host.mydomain.com IP address where i access the domestic.mydomain.com file manager
What my laravel-echo-server.json looks like:
{
"authHost": "https://example.com",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "xxxx",
"key": "xxxxxxxx"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": false,
"host": "127.0.0.1",
"port": "6001",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": false,
"allowOrigin": "",
"allowMethods": "",
"allowHeaders": ""
}
}
How I deploy my laravel-echo:
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,
});
window.Echo.channel('session-expired')
.listen('sessionExpired', (e) => {
setTimeout(location.reload(), 3000);
});
}
And when I run laravel-echo-server start It successfully initialises and shows running on 127.0.0.1 on port 6001
Then here is my apache reverse proxy config /etc/httpd/conf/httpd.conf:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
# mod_proxy setup.
ProxyRequests Off
ProxyPass /socket.io http://127.0.0.1:6001
ProxyPassReverse /socket.io http://127.0.0.1:6001
<Location "/socket.io">
Order allow,deny
Allow from all
</Location>
My problem is when I open my website the polls return a set of OK and 404 responses simultaneously, but it doesn't join any channels within my socket.io. After lots of testing i figured that the proxy does redirect but i doubt it's hitting the particular one I want.
Heres the HTML responses for my 404, which is not my server's configured 404 response:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /</pre>
</body>
</html>
It runs perfectly on my local server but I need to make it run on my production server.
Finally got it.
While my website must still bear an SSL, the solution is to get Apache to redirect /socket.io to http://localhost:6001/socket.io already configured for redis. Then use 2.2.3 version of socket io.
So my laravel-echo-server.json isn't configured for SSL.
Heres my 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"
}
}
How I utitlizes 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,
});
}
And my apaxhe config within my SSL virtualhost for my domain:
RewriteEngine On
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
In addition it would require a Node js process manager to keep the laravel-echo-server running. So I created echo-server.json and placed the following code.
{
"name": "apps",
"script": "laravel-echo-server",
"args": "start"
}
Next, I install pm2 process manager. npm install pm2 -g and started my service pm2 start echo-server.json --name="apps".
Lastly I use pm2 list to view all my services and pm2 startup to keep my services running.
I am working on making a real-time notifications with Laravel-Redis-Socketio-LaravelEcho. So far, i am able to broadcast to pubic channel but stuck with private channel.
My bootstrap.js:
import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
Laravel-echo-server.json:
"authHost": "http://localhost",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "{{Omitted purposely}}",
"key": "{{Omitted purposely}}"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": ""
In my notification class, i have broadcastOn() as:
public function broadcastOn() {
return new PrivateChannel('my-channel');
}
And my-client side is:
Echo.private('my-channel')
.notification((notification) => {
console.log('I am here');
});
Everything is working fine with Public Channel but With Private Channel, command line shows the following after starting laravel-echo-server :
Error: Connect ECONNREFUSED 127.0.0.1:80.
Error sending authentication request.
You have to add broadcast authentication routes by uncommenting the below line in config/app.php
App\Providers\BroadcastServiceProvider::class,
so that in your routes/channel.php will check for particular guard and return 1 or 0 depending on your conditions
I'm using laravel-echo with redis driver to broadcast notifications. It works perfectly on my local system. But on my server, I'm getting ERR_CONNECTION_TIMED_OUT error. Browser console displays http://ex.example.com:6001/socket.io/socket.io.js net::ERR_CONNECTION_TIMED_OUT.
I have not any knowledge about socket and redis. So I just have followed instruction of laravel official doc and laravel-echo-server. and made just one change from here. But with help of that change, I'm able to let execute remaining js script. Issue of socket.io.js is still unsolved (Also in github).
Here is steps which I have followed.
Follow Laravel Official Doc
Install Redis-Server
Install laravel-echo-server
Install socket.io-clent in my project
js
import Echo from "laravel-echo"
window.io = require('socket.io-client'); //suggested in github issue
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
laravel-echo-server.json
{
"authHost": "http://ex.example.com",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "edbf10287972d875",
"key": "96403c9f93e1a2d86185e2d21aa0fae1"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": ""
}
If anyone knows the solution, it will be appreciated.
This may sound simple, but did you check the firewall settings on your server?
edit: thanks to #AkshayVaghasiya for sharing the instructions for setting up your firewall correctly [read here].