laravel-echo-server
laravel-echo-server copied to clipboard
Echo HTTP API call through nginx proxy
Hello!
I have laravel-echo container running behind the nginx proxy in other container with config:
location /connector/ {
proxy_pass http://echo-web:6001/socket.io/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
Echo connecting and works fine. When send Echo HTTP API (https://github.com/tlaverdure/laravel-echo-server#http-api) request to https://server:6001/socket.io/apps/[app-id]/channels?auth_key=[auth-key] everything works fine too.
But when i send API request through proxy https://server/connector/apps/[app-id]/channels?auth_key=[auth-key]
i receive:
{ "code": 0, "message": "Transport unknown" }
Hi! I'm facing the same problem. Do you have a solution for it? Thanks!
Sorry, don't remember. But i solve it.
This is what i found in git, you can try (one line changed)
const echo = window.Echo = new Echo({
broadcaster: 'socket.io',
host: echoPath ? { path: `/${echoPath}` } : echoHost,
transports: ['websocket'], // <- maybe this line helps
});
The nginx config was the problem. I fixed it with this additional lines:
location /socket.io/apps {
proxy_pass http://localhost:6001/apps;
proxy_http_version 1.1;
}
window.Echo = new EchoLibrary({ broadcaster: 'socket.io', host: window.location.hostname, });
it works without server:6001 and without server/socket.io
You have to supply only host name, without port and catalog. Else it gives invalid namespace error.
upstream cluster_frontend {
least_conn;
server laravel:80;
}
upstream cluster_socketio {
least_conn;
server socketio:6001;
}
server {
listen 80;
location /socket.io {
proxy_pass http://cluster_socketio;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location / {
add_header Cache-Control "no-cache";
gzip_vary on;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
proxy_pass http://cluster_frontend;
include /etc/nginx/conf.d/proxy_params;
}
}
The nginx config was the problem. I fixed it with this additional lines:
location /socket.io/apps { proxy_pass http://localhost:6001/apps; proxy_http_version 1.1; }
thanks