Closed ax-ross closed 2 years ago
Hello!
The only thing I noticed here is that your app
in docker-compose does not expose any ports. I suppose it should expose 9000? Probably it's not the root cause, it's very hard to debug without a way to reproduce - if the idea with the port won't work out please post this all as a Github repo so I could run docker compose up
and I'll try to look.
In general, the error you are observing indicates that there is no network connectivity between Centrifugo and app
Unfortunately, its didn't help me(
Many hours later, I solved this problem... I changed host proxy_connect_endpoint in centrifugo config file from nginx to webserver (yes, I'm so bad(( ). But not I have new problem... I get 419 error when I'm trying to connect to /centrifugo/connect, It's mean, what csrf tokeт was not transferred (I have "X-XSRF-TOKEN" header in my proxy_http_headers centrifugo config now, but I think csrf token not sent from centrifugo-js).
And one more question, if I understood correctly, I need to specify channel (I use user limited channel) when I connecting from js. (Do I need to use const sub = centrifuge.newSubscription("personal:user#1") instead of const sub = centrifuge.newSubscription("personal");)
Sorry for wasting your time, but its turned out to be hard for me(
Since Centrifugo issues a POST request to your backend when using connect proxy – then Laravel may automatically require CSRF token to be presented in request headers. But since this is not a form submission, you can safely disable CSRF check for the endpoint which serves connect requests from Centrifugo. Centrifugo uses POST just as a way to pass some JSON body in convenient way.
You can't control headers which are sent in WebSocket case (browsers do not have API to set custom headers), your browser only sends cookies for the target domain, and that's all. There are possibilities though to append CSRF token to Centrifugo endpoint URL params for example, then transform it to header on load balancer or reverse proxy level. But I don't think you need to do this in this case.
Also, make sure you are strict in allowed_origins
, avoid using *
.
Closing, please use community rooms when asking for a help.
Hello, I using centrifugo + nginx + laravel + vuejs via docker compose. I used this guide for settings my app https://centrifugal.dev/blog/2021/12/14/laravel-multi-room-chat-tutorial and tried adapt it for centrifugo v4. I have: "centrifuge-js": "^3.0.1", "denis660/laravel-centrifugo": "^3.0", centrifugo/centrifugo:v4, laravel 9
When I try to connect to channel, I get an error in my docker compose logs:
centrifugo | {"level":"error","client":"c0442434-aa3c-4fa6-8521-0c6b4f756890","error":"HTTP request error: Post \"http://nginx/centrifugo/connect\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)","time":"2022-10-22T08:13:52Z","message":"error proxying connect"} centrifugo | {"level":"info","client":"c0442434-aa3c-4fa6-8521-0c6b4f756890","code":100,"command":"id:9 connect:{name:\"js\"}","error":"internal server error","reply":"id:9 error:{code:100 message:\"internal server error\" temporary:true}","user":"","time":"2022-10-22T08:13:52Z","message":"client command error"} I tried to set timeout in my js: ( const centrifuge = new Centrifuge('ws://127.0.0.1:8000/connection/websocket', { debug: true, timeout: 20000 }); and in my centrifugo config: "proxy_connect_timeout": "10s" but its not working for me.
Please, help me to fix it. Below I attach my configs:
nginx: https://pastebin.com/k55iqvqs centrifugo: https://pastebin.com/wi3AcEz6 docker-compose: https://pastebin.com/qah9kgeT js: