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_passsays (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
- 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". - Test the config after any change with
sudo nginx -t. It tells you the file and line of any error. - For 502, check your app is running and listening on the port in
proxy_pass. See 502 Bad Gateway. - For 504, find the slow request in your app. Raising
proxy_read_timeoutis only a stopgap. - For 413, raise
client_max_body_sizeto fit your largest expected upload. - Reload with
sudo nginx -s reloadoncenginx -tpasses.
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 reportYour first report is free, no card needed. Then A$50 a month, up to 10 domains. Read-only: it never changes anything.
Sources
- nginx: Beginner's Guideofficial docs
you 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 .
- 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.
- nginx: Module ngx_http_proxy_moduleofficial docs
Defines a timeout for reading a response from the proxied server.
- nginx: Module ngx_http_core_moduleofficial docs
Sets 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.
- nginx: Module ngx_http_proxy_moduleofficial docs
Default: proxy_read_timeout 60s;
- nginx: Beginner's Guideofficial docs
To 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