Can someone please help me regarding ratchet library on nginx
I'm new to vps hosting and my website is hosted on digitalocean, I'm using ratchet library (http://socketo.me) for my php application. It's working on localhost but not in server.


In server.php:

   `<?php
     use Ratchet\Server\IoServer;
     use Ratchet\Http\HttpServer;
     use Ratchet\WebSocket\WsServer;
     use MyApp\Chat;

    require dirname(__DIR__) . '/vendor/autoload.php';

    $server = IoServer::factory(
        new HttpServer(
            new WsServer(
                new Chat()
            )
        ),
        8080
    );

    $server->run();`


In my client side code:

`if(window.WebSocket){
       var conn = new WebSocket('wss://mydomain.com:8443');
       ......
       ......
    }`

In my nginx configuration file (/etc/nginx/sites-available/mydomain.com )

`upstream websocket{
    server 127.0.0.1:8443;
}

 map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }
server {
    server_name mydomain.com www.mydomain.com;
    root /var/www/www.mydomain.com;

    index index.html index.htm index.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
     }

    location ~ /\.ht {
        deny all;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
   location /ws/ {
            proxy_pass http://websocket;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
     }

 }
server {
    if ($host = www.mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name mydomain.com www.mydomain.com;
    return 404; # managed by Certbot



}

In my console it says

"WebSocket connection to 'WebSocket connection to 'wss://mydomain.com:8443/' failed: Error during WebSocket handshake: Unexpected response code: 522"

note: I have setup my dns records on cloudflare. I'm new to this stuff, can somebody please guide me.

Thanks in advance!`
