antoniodipinto / ikisocket

🧬 WebSocket wrapper with event management for Fiber https://github.com/gofiber/fiber. Based on Fiber WebSocket and inspired by Socket.io
MIT License
123 stars 21 forks source link

426 Upgrade Required #9

Closed Nv7-GitHub closed 3 years ago

Nv7-GitHub commented 3 years ago

I copied the code from the example into my test server. It worked fine on localhost using https://www.websocket.org/echo.html, but when I deployed it and used wss://api.nv7haven.tk/ws/123?v=1.0, it is returning a 426. I put a print statement, and its returning a 426 because IsWebsocketUpgrade is returning false. Why is it returning false, and how can I fix this?

antoniodipinto commented 3 years ago

Hi, how are you configuring the SSL for WSS? If you're using an NGINX proxy, make sure that the redirection proxy is also set to redirect. Since it's working on your localhost, Fiber should not have any issue. Ikisocket it's just a wrapper on top of Fiber.

Keep me posted if you discover that is a bug in ikisocket. Thanks

Nv7-GitHub commented 3 years ago
Screen Shot 2021-03-09 at 3 53 49 PM

Above is the Nginx config, is something wrong with it?

antoniodipinto commented 3 years ago

Seems to be fine. But if you copied my example, why the port is different on your proxypass?

In any case, if you said that it's working on your local machine, Ikisocket and Fiber should be both ok.

So the issue should be located somewhere else

antoniodipinto commented 3 years ago

After some digging, I've found this doc https://www.nginx.com/blog/websocket-nginx/ and some services want Upgrade and not upgrade as Connection Maybe this can help you.

I will leave this open another day, maybe you can solve the issue and you can write here the solution, so will be helpful also for others with the same issue

Nv7-GitHub commented 3 years ago

Are there any headers that aren't being passed through the Nginx proxy that could be causing IsWebsocketUpgrade to return false? Is there a way to see what headers fasthttp checks?

antoniodipinto commented 3 years ago

Via Fiber you can check all the headers inside that .Use()

Check here how to retrieve the headers https://docs.gofiber.io/api/ctx#get

Nv7-GitHub commented 3 years ago

I tried printing the Connection header, and for some reason it says "close". The nginx config sets the "Connection" header, so why would it be close? It appears that close is the default header, so is nginx not setting the header?

antoniodipinto commented 3 years ago

It seems that you have some issues between your proxy and your application server. If you try to connect directly bypassing the proxy, it works, right?

Nv7-GitHub commented 3 years ago

Yes, it works on localhost.

antoniodipinto commented 3 years ago

I understand that, but when you deploy it on a server, it works? I mean, instead of connecting to your domain (using NGINX), connecting directly to the IP of the server where the application is deployed (without proxy), it works? If you connect directly to 172.18.0.12:?

antoniodipinto commented 3 years ago

I'll close this issue because seems to be a configuration issue more than a library issue