Nginx error

Updated 11 October 2026

Short answer

An error page that says "nginx" at the bottom usually isn't Nginx's fault. Nginx is passing on a problem with the app behind it. 502 Bad Gateway: your app is down or unreachable. 504 Gateway Timeout: your app is too slow. 413 Request Entity Too Large: an upload exceeds Nginx's size limit. If Nginx itself won't start or reload, it's almost always a typo in the config. Run nginx -t to find it, and read /var/log/nginx/error.log for everything else.

What's the problem

Visitors see an Nginx-branded error page (502, 504, 413, 403 or 404), or Nginx fails to start or reload after a config change.

Why it happens

  • The app behind Nginx is down or on a different port than proxy_pass says (gives 502).
  • The app is slower than proxy_read_timeout (gives 504; the default is 60 seconds).
  • Uploads are larger than client_max_body_size (gives 413).
  • File permissions or a missing index file (gives 403).
  • A config syntax error, so Nginx refuses to start or reload.

How to fix it

  1. Read the Nginx error log, usually /var/log/nginx/error.log. It names the exact problem, such as "connect() failed (111: Connection refused) while connecting to upstream".
  2. Test the config after any change with sudo nginx -t. It tells you the file and line of any error.
  3. For 502, check your app is running and listening on the port in proxy_pass. See 502 Bad Gateway.
  4. For 504, find the slow request in your app. Raising proxy_read_timeout is only a stopgap.
  5. For 413, raise client_max_body_size to fit your largest expected upload.
  6. Reload with sudo nginx -s reload once nginx -t passes.

What Preventionlabs checks

One click runs the full report on your domain. For this problem it shows whether your site loads, how fast, and where its redirects go; uptime checked every 5 minutes, with an email when the site goes down and when it is back. With Cloudflare connected, it also shows which pages returned server errors (5xx) to visitors, and when; recent deploys and account changes, with their times. It can't log in to your server, so memory, disk and process problems show up in your host's dashboard and logs.

Run your free report

Your first report is free, no card needed. Then A$50 a month, up to 10 domains. Read-only: it never changes anything.

Sources

  1. nginx: Beginner's Guideofficial docsyou may try to find out the reason in access.log and error.log files in the directory /usr/local/nginx/logs or /var/log/nginx .
  2. nginx: Command-line parametersofficial docs-t — test the configuration file: nginx checks the configuration for correct syntax, and then tries to open files referred in the configuration.
  3. nginx: Module ngx_http_proxy_moduleofficial docsDefines a timeout for reading a response from the proxied server.
  4. nginx: Module ngx_http_core_moduleofficial docsSets the maximum allowed size of the client request body. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client.
  5. nginx: Module ngx_http_proxy_moduleofficial docsDefault: proxy_read_timeout 60s;
  6. nginx: Beginner's Guideofficial docsTo reload configuration, execute: nginx -s reload

Preventionlabs is independent and not affiliated with Nginx. Product names are used only to describe the problem.

← All of Server