Websocket doesn't work on prod with CF, works fine locally

What is the name of the domain?

volt.im, ws.volt.im (websocket server)

What is the issue you’re encountering

Websocket doesn’t work on prod with CF, works fine locally

What steps have you taken to resolve the issue?

nginx config

server {
   server_name ws.volt.im;
        listen 80;
        listen [::]:80;

        location / {
         proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $remote_addr;
             proxy_set_header Host $host;
             proxy_pass http://127.0.0.1:8087;
          proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_redirect off;
    proxy_read_timeout 86400;
    proxy_send_timeout 86400;
}

}

Copied some nginx headers from a forum discussion here. Used to help, but it no longer works.

To reproduce

https://volt.im/login
login: cftest
password: 123

then go to

https://volt.im/s/volt/test

type anything in chat and press enter. Websocket connection doesn’t work (very rarely it does), have to refresh the page to see the message.

On localhost it works 100% of the time.

Either should be WS and HTTP or WSS and HTTPS.
You’r link and domain is over HTTPS, therefrom you should consider using WSS.

Are WebSockets enabled at Cloudflare dashboard → Network → WebSockets? :thinking:

Should be running over a compatible HTTP(S) port with Cloudflare as well:

For Nginx, even over HTTP and Flexible SSL, it was working for my case.

I’d suggest you to check below topics, all posts for troubleshooting and more help:

Either not using WebSockets, or something is working.
On the Console I see Socket via WSS, but in Network tab only HTTPS requests, no WS(S) connection made.

1 Like

It uses wss:

from console:

NEW SOCKET url="wss://ws.volt.im/

from js code:

const socket_url_prod = `wss://ws.volt.im`;

Cloudflare dashboard → Network → WebSockets
is enabled

I have flexible SSL.

Do I perhaps need to set up secure ws on the server via letsencrypt and use Full SSL?

This is the topic I copied my nginx config from initially. And it used to work fine. Then it stopped for some reason.