WebSocket Not Working in Production – Docker Server Rejects Connections
Hi Wasp team,
I am experiencing an issue with WebSocket connections in my self-hosted production environment. After investigating, I found that the Docker server itself is rejecting WebSocket connections.
Issue Summary:
WebSockets work perfectly in my local environment.
REST API works fine in production, so Nginx is correctly forwarding requests to the backend.
However, WebSocket connections fail in production, and after debugging, I found that the Docker server is not accepting WebSocket requests.
What I’ve Tried:
Checked Nginx configuration → WebSocket settings are correctly set (proxy_set_header Upgrade $http_upgrade;, etc.).
Tested direct WebSocket connection inside the server (curl -i -N -H "Upgrade: websocket" ...) → Docker returns "400 Bad Request - Transport unknown".
Checked logs from my backend service inside the Docker container → No WebSocket connections are being registered, meaning the requests are not reaching socket.io.
It seems that WebSocket requests are being blocked or not properly handled inside the Dockerized Wasp backend.
Question:
How should I configure Wasp + Docker to ensure WebSockets work correctly in production? Are there any specific settings required for WebSocket support in a self-hosted Docker setup?
Thanks in advance for your help!
Best regards,
Taha
6 Replies
Hi @Taha. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Thank you for your detailed question about WebSocket issues in a self-hosted Docker production environment for Wasp, Taha. I'll do my best to provide some guidance based on the available information.
The knowledge sources don't contain specific information about your exact setup or issue. However, I can offer some general advice and point you to relevant resources that might help:
1. Dockerfile Configuration:
Wasp generates a Dockerfile for deploying the server to production. If you've customized this Dockerfile or have a custom build process, you might need to ensure it's properly configured for WebSocket support. The Migration guide from 0.11.X to 0.12.X mentions changes to the default Dockerfile. You might want to compare your current Dockerfile with the latest one generated by Wasp.
2. Environment Variables:
Make sure you've set the correct environment variables for your production setup. The Server Configuration documentation mentions that you can configure the server using environment variables. Ensure that
WASP_WEB_CLIENT_URL
is set correctly in your production environment.
3. WebSocket Configuration:
Review your WebSocket configuration in the Wasp file. The WebSockets documentation explains how to set up WebSockets in Wasp. Ensure that your webSocket
configuration in the Wasp file is correct and that the webSocketFn
is properly implemented.
4. Docker Compose:
If you're using Docker Compose, you might want to review your docker-compose.yml
file. While there's no specific example in the knowledge sources, the GitHub issue about deployment to bare metal mentions that a typical setup might include containers for PostgreSQL, server, client, and optionally a reverse proxy.
5. Debugging:
For further debugging, you might want to check the server logs inside the Docker container. The WebSocket connection should be handled by the Wasp server, so if it's not reaching there, there might be an issue with how the Docker container is exposing the WebSocket port or how the requests are being routed.
Unfortunately, the knowledge sources don't provide a specific solution to your Docker server rejecting WebSocket connections. This seems to be a more specific issue that might require deeper investigation into your particular setup.
If these suggestions don't help resolve the issue, I recommend reaching out to the Wasp team directly through their GitHub issues or Discord community for more tailored support. They might be able to provide more specific guidance based on your exact setup and configuration.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Taha, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?my webSocket.ts file :
What are you using for self-hosting, it's just a VPS with Nginx + Docker?
yes
Wohooo @Taha, you just became a Waspeteer level 2!
We'll need to take a look at your Nginx config. Also, did you do something custom with Docker for Wasp server? Did you do something with the VPS firewall? Share any relevant files 🙂