• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Issue Websocket connection failing on Plesk server

imitev

New Pleskian
Server operating system version
Ubuntu 22.04.4
Plesk version and microupdate number
18.0.60
I'm setting up a server on Plesk with a React.js and Node.js application, containing a client and server side.

Below the socket in my client config file:

export const socket = io('wss://domain.name:3000', {reconnect: true, transports: [ 'websocket' ] });

And this is the setup on the server side:

JavaScript:
ServerConfig.port = 3000;



const server = this.app.listen(ServerConfig.port,  () =>  {

        console.log('Ready on port %d', server.address().port);

    }),

I'm 100% sure this configuration works as I've tested it locally, as well as it's being used on another server which doesn't use Plesk.

I've set up the domains for the client and server, and when I now open my client I get the error message:

main.js:75 WebSocket connection to 'wss://domain.name:3000/socket.io/?EIO=3&transport=websocket' failed:

I don't now where the configuration mistake lies, I've also tried almost everything in the nginx.conf files of both the subdomain and the config file in /etc/nginx/nginx.conf for example:

  • Added the location block in Plesk with the correct IP address and port:

NGINX:
location / {
    proxy_pass http://ip.address:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

  • Also tried this with a localhost IP, since both services run on the same server. (just on different subdomains and ports)
  • Create a custom nginx file with the following:
NGINX:
upstream websocket {
      ip_hash;
      server ip.address:3000 weight=5;
      keepalive 10;
}

NGINX:
server {
    listen ip.address:443;
    ssl_certificate /opt/psa/var/certificates/certificate;
    ssl_certificate_key /opt/psa/var/certificates/key;

    server_name domain.name service.domain.name;

    location / {
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}


and included it in the /etc/nginx/nginx.conf file. For this option I got errors if tried to place in the Additional nginx directives regarding "upstream" and "server".

Nothing seems to work and I keep getting the same error. Any suggestions help!
 
I am not completely sure, but three things come to mind that might be worth checking.

1) Did you disable proxy mode for the domain in Plesk?
2) I believe that the connection wss://domain.name:3000 would require port 3000 to be opened on the firewall. Did you check if port 300 is open?
3) Which IP address is used here proxy_pass http://ip.address:3000;? This should be local (127.0.0.1), because otherwise the proxy requests are routed externally, which I think won't work.
 
Back
Top