I'm running a WebSocket server on node with uWebSockets.js. Deployed via pm2 (non-clustered) and sitting behind Nginx 1.18.0, setup as a reverse proxy, also behind CloudFlare.
Scenarios:
- locally (works via browser and Postman)
- via WAN directly: open ports (works via browser and Postman)
- via Nginx (works only via Postman)
- via CloudFlare and Nginx (works only via Postman)
I've checked multiple times that I'm connecting to the same domain/IP.
I've tried http and https and it's always the same. Browser simply can't establish a connection to the server without giving any helpful errors (the connection is closed immediately).
I do want to use some custom logic for upgrade, but I've tested without modifying upgrade as well and nothing changes.
I've also added comments in beginning of upgrade and it never gets triggered.
Connection does come in via Nginx, but I only see an entry in access_log, nothing else.
I've tried various combinations of Nginx configuration below to no avail, even from the simplest configuration as shown here https://nginx.org/en/docs/http/websocket.html
location /ws/ {
proxy_pass http://backend-ws;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 86400;
proxy_next_upstream_timeout 60;
proxy_next_upstream_tries 3;
proxy_buffering off;
}
