504 Gateway time-out, nginx, nodejs

June 3, 2018 1.4k views
Nginx Node.js Ubuntu 16.04

First of all. The autorenew of my SSL certificate failed for some unknown reason. After re-installing the ssl certs from let's encrypt, nginx gave me 504 gateway-timeout. I checked the error log and this appear.

2018/06/03 12:37:32 [error] 9128#9128: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 84.253.220.134, server: cloudland.com, request: "GET / HTTP/2.0", upstream: "http://127.0.0.1:3000/", host: "cloudlandmusic.com"

So I have nginx reverse proxy for a node js app.
This is my nginx config:


# HTTP — redirect all traffic to HTTPS
server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;
    return 301 https://$host$request_uri;
}

# HTTPS — proxy all requests to the Node app
server {
    # Enable HTTP/2
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name cloudland.com;

    # Use the Let’s Encrypt certificates
    ssl_certificate /etc/letsencrypt/live/cloudlandmusic.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/cloudlandmusic.com/privkey.pem;

    # Include the SSL configuration from cipherli.st
    include snippets/ssl-params.conf;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://localhost:3000/;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
    }
}


My node app is running with pm2

this is the nginx status:

nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2018-06-03 12:35:25 UTC; 16min ago
  Process: 8883 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 9122 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 9118 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 9127 (nginx)
    Tasks: 2
   Memory: 2.1M
      CPU: 66ms
   CGroup: /system.slice/nginx.service
           ├─9127 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
           └─9128 nginx: worker process

But I think nginx is not the problem, for some reason my app is not working, but I don't know how to debug it, thanks for any help

1 Answer

This happens due to lack of RAM.......check this by using pm2 log or pm2 monit commands........

Have another answer? Share your knowledge.