1

I have a really big issue with my digitalocean droplet can you help me please,

I have a nodeJS app and it's work with MySQL and I use Nginx + Ubuntu

but for no reason, I got 502 bad gateway

I have upgraded my droplet and after 3 days my app down again

but the really weird on my digitalocean platform the CPU % and Memory is good

and now I have upgraded my droplet to the last package

can you help me please

and when I execute this command sudo tail -30 /var/log/nginx/error.log

I got this error

[error] 989#989: *6611 connect() failed (111: Connection refused) while connecting to upstream, client:

and I want to note that my app it's already work well more than 1 year

this is the nginx code

server {

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name domain.app;

        location / {
                proxy_pass http://localhost:3001;
                proxy_http_version 1.1;
                proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/domain.app/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain.app/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 = domain.app) {
        return 301 https://$host$request_uri;
    } # managed by Certbot



        server_name domain.app;
    listen 80;
    return 404; # managed by Certbot


}

Thank you for helping

Gabrialoo
  • 41
  • 3
  • You may wish to review this URL for tips - https://www.digitalocean.com/community/questions/502-bad-gateway-nginx-2 If not resolved, Additional information request. RAM size, # cores, any SSD or NVME devices on MySQL Host server? Post on pastebin.com and share the links. From your SSH login root, Text results of: B) SHOW GLOBAL STATUS; after minimum 24 hours UPTIME C) SHOW GLOBAL VARIABLES; D) SHOW FULL PROCESSLIST; E) STATUS; - not SHOW STATUS; just STATUS; G) SHOW ENGINE INNODB STATUS; for server workload tuning analysis to provide suggestions. – Wilson Hauck Apr 03 '21 at 19:12

1 Answers1

4

I had a similar issue with NodeJS (express) and Application Load Balancer (AWS). The issue was in the keep-alive timeout configuration, the NodeJS application default timeout was set to a shorter period than the timeout configured on the load balancer which resulted in the server dropping the connection in the middle of a request (made from the load balancer).

A simple fix was setting the server.keepAliveTimeout to a higher number than configured on the load balancer. This is a great post that helped me and it goes into much details

The default keep alive for nginx is 75 sec; The default keep alive for NodeJS is 5 sec.