Wss not working

I have tried a bunch of things,

Basically i have set up strict full ssl and it all seems to work, the only thing that’s not working is my wss connection. I know you can switch it on and off in the network tab, so it’s on,

my nginx looks somewhat like this:

server {
    listen 80;
    listen [::]:80;
    server_name <domain>.com www.<domain>.com api.<domain>.com ws.<domain>.com;
    return 302 https://$server_name$request_uri;
}


server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    ssl on;
    ssl_certificate /etc/ssl/pem;
    ssl_certificate_key /etc/ssl/key;

    root /var/www/forex-crypto-utils/client/dist/client;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name <domain>.com;

    location / {
        try_files $uri $uri/ /index.html;
    }

    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 365d;
    }
}


server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    ssl on;
    ssl_certificate /etc/ssl/pem;
    ssl_certificate_key /etc/ssl/key;

    server_name api.<domain>.com;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://localhost:2096;
        proxy_ssl_session_reuse off;
        proxy_cache_bypass $http_upgrade;
    }

}

where is my domain, my rest api and graphql are both running on 2096. I access ws locally on ws://localhost:2096/graphql, all my http calls are working, my graphql playground works find except for wss calls :

{

“error”: “Could not connect to websocket endpoint wss://api./graphql. Please check if the endpoint url is correct.”
}

when i go directly to the wss url i get the following error:

might be temporarily down or it may have moved permanently to a new web address.

ERR_DISALLOWED_URL_SCHEME

From https://www.nginx.com/blog/websocket-nginx/:

For NGINX to send the Upgrade request from the client to the backend server, the Upgrade and Connection headers must be set explicitly

You don’t appear to be doing that in your config. Try following the instructions in that article.

I guess that works, it took some time for cloudflare, but now it works

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.