Cloudflare only allows port 8443 for sockets. Try that port instead and it should work ;)
Jan 11, 2020
2
Level 2
Laravel-echo-server for production - WebSocket connection problem
Hi, I tried to run socket.io on top of my app in production server. Using https, redis, also allow CORS and also CloudFlare. Unfortunately, it got no error on console. I also allow 2053 port in my server. These are my configurations.
My app.js
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':2053',
transports: ['websocket', 'polling'],
auth: {
headers: {
Authorization: 'Bearer key'
}
}
});
My laravel-echo-server.json
{
"authHost": "https://url.com",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "app-id",
"key": "app-key"
}
],
"database": "redis",
"databaseConfig": {
"redis": {
"port": "6379",
"host": "127.0.0.1",
"password": "password"
},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": false,
"host": null,
"port": "2053",
"protocol": "https",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "/etc/ssl/certs/url.com.pem",
"sslKeyPath": "/etc/ssl/private/url.com.key.pem",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": true,
"allowOrigin": "https://url.com",
"allowMethods": "GET, POST",
"allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
}
}
My nginx conf
location /socket.io {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:2053;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
I tried to telnet the Cloudflare URL with port 2053 and got this result
HTTP/1.1 400 Bad Request
Server: cloudflare
Date: Sat, 11 Jan 2020 13:26:27 GMT
Content-Type: text/html
Content-Length: 155
Connection: close
CF-RAY: -
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare</center>
</body>
</html>
Connection closed by foreign host.
Tried to open https://url.com:2053/socket.io/?EIO=3&transport=websocket
{
code: 3,
message: "Bad request"
}
Is there something I'm missing on my config?
Please or to participate in this conversation.