php – I can’t connect to websockets with Nginx + Ratchet using SSL from Let’s Encrypt in EC2


I’m trying to start my chat server that uses the Ratchet (PHP) library, but I’m not getting it, does everything indicate that I need a reverse proxy? The server starts perfectly on the php script console, but on the Google console, it reports a connection timed out error, so what can that be?

I use EC2 to host my website, and I have Let’s Encrypt’s SSL certificate, along with the Nginx web server, what can I do to start a websocket connection with HTTPS and Nginx?

Do I need to make reverse proxy? How can I do it in Nginx configuration? My link from the chat is www.example.com/chat.php

Which port should I use in the PHP script and JavaScript code, 8080 or 8443?

Nginx Configuration:

    server {
    
            root /var/www/example.com/html;
            index index.html index.php index.htm index.nginx-debian.html;
    
            server_name example.com www.example.com;
 
    
            location ~ .php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        }
            location / {
                    proxy_set_header        Host $host;
                    proxy_set_header        X-Real-IP $remote_addr;
                    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header        X-Forwarded-Proto $scheme;
    
                    proxy_pass          http://localhost:8080;
                    proxy_read_timeout  90;
                    proxy_redirect      http://localhost:8080 https://example.com;
                    #try_files $uri $uri/ =404;
            }
    
    
        listen (::):443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/example.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.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


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

        listen 80;
        listen (::):80;

        server_name example.com www.example.com;
   return 404;  # managed by Certbot



}
server {
        listen 80;
        listen (::):80;

        access_log /var/log/nginx/reverse-access.log;
        error_log /var/log/nginx/reverse-error.log;

        location / {
                    proxy_pass http://127.0.0.1:8080;
  }
}