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.


    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()


In my client side code:

           var conn = new WebSocket('wss://mydomain.com');

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

 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

    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 ‘wss://mydomain.com/’ failed: Error during WebSocket handshake: Unexpected response code: 200”

note: my domain has ssl. I’m new to this stuff, can somebody please guide me.

Thanks in advance!

edited by MattIPv4
Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!