Answer the question
In order to leave comments, you need to log in
How to defeat 502 error when working with Laravel-echo-server?
I haven't been able to find a reason for a week now. Works fine on dev server, but not on production.
I am using Cloudflare. I set up a proxy, laravel echo works, it accepts events. But when I try to connect to the socket, I get an error: WebSocketError: Unexpected status code received (502 Bad Gateway)
Environment:
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"
}
}
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";
}
}
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!
$ curl 127.0.0.1:6001
> OK
websocat wss://domain.tld:8443/ws
websocat: WebSocketError: Received unexpected status code (502 Bad Gateway)
Answer the question
In order to leave comments, you need to log in
I don't know what the problem is, but I found a solution.
I updated Nginx to 1.19.1, may have installed additional modules when trying to build Nginx from source.
I installed npm not globally, but locally - maybe this also somehow affected.
Warning: this only works if you write location /socket.io.
No other location works, just this one!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question