0

I recently added a reverse proxy to my website to make websockets connections over SSL, however, I am experiencing a 502 Bad Gateway issue. Whenever I open the website, css files, js and images are not loaded, and when opening the Google console, there are 502 bad Gateway errors, so this seems to be a problem in my reverse proxy configuration, how can I resolve this?

Console:

net::ERR_ABORTED 502 (Bad Gateway): it appears because the page can't open js or css files

Failed to load resource: the server responded with a status of 502 (Bad Gateway): it appears because the website doesn't shows the images, it is a loop in the Google Console

Nginx Configuration:

upstream websocketserver {
        server localhost:8080;
}


server {
    root /var/www/example.com/html;
    index index.html index.php index.htm index.nginx-debian.html;

    server_name example.com;


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

    listen 443;
    ssl on;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    access_log /var/log/wss-access-ssl.log;
    error_log /var/log/wss-error-ssl.log;
    location / {
                proxy_pass http://websocketserver;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                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 https;
                proxy_read_timeout 86400; # neccessary to avoid websocket timeout disconnect
                proxy_redirect off;
        }

}

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



}

What can I do to solve it? Is something wrong in my Nginx Configuration?

Nginx Logs

2020/09/25 15:57:44 [error] 86297#86297: *16 connect() failed (111: Connection refused) while connecting to upstream, client: 131.118.124.30, server: mysite.com, request: "GET /duck-image.jpg HTTP/1.1", upstream: "http://127.0.0.1:8080/duck-image.jpg", host: "mysite.com", referrer: "https://example.com/index.php". What can I do? Do I need to change the upstream directive? I mean change localhost:8080 to the domain as mysite:8080? Or the ip, as an example 9.9.9.9:8080?

0 Answers0