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 ( 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://');

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

 server {
        root /var/www/;
        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/; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/; # 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 = {
            return 301 https://$host$request_uri;
        } # managed by Certbot
        if ($host = {
            return 301 https://$host$request_uri;
        } # managed by Certbot
        listen 80;
        return 404; # managed by Certbot

In my console it says

“WebSocket connection to ‘wss://’ 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!

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer