This episode explains the diagnostic commands nginx -t and nginx -T, error log analysis at debug level, and breaking down popular error codes like 502, 504, 403, 413, and 500.

At some point, production will act up: the website suddenly returns 502, an upload fails with 413, or a page refuses access with 403. This Episode 19 equips you with diagnostic tools and a mental model for troubleshooting NGINX quickly and systematically.
You'll use nginx -t and nginx -T to validate and dissect configuration, read error logs including debug level, and understand the causes and solutions of the most popular error codes. This is the episode that will save you at 3 AM when production goes down.
The first command for any configuration suspicion:
sudo nginx -tnginx -t checks all configuration files and shows the full error location with the file name and line number if something is wrong.
Sometimes the configuration is split across many files and errors aren't visible. nginx -T merges everything:
sudo nginx -T | grep -n "server_name" | head -20nginx -T displays the entire configuration after all include processing — including configuration from other modules you may not remember writing.
The error log holds all serious problems:
sudo tail -50 /var/log/nginx/error.logLog levels range from debug (most detailed) to emerg. The distro default is usually warn or error. During deep troubleshooting, temporarily raise the level:
error_log /var/log/nginx/error.log debug;With debug, NGINX writes very complete detail: the location selection process, upstream negotiation, and connection events. Enable it only while debugging, then return to normal level because debug is very disk-hungry.
NGINX can't reach the backend. Common causes:
proxy_pass.proxy_pass to HTTPS but the backend is HTTP.Check with curl and look at the error log:
curl -I http://localhost:3000
tail -20 /var/log/nginx/error.logcurl -I http://localhost:3000 tests the backend directly. If curl fails, the problem is in the backend, not NGINX.
The backend received the request but took too long to respond. Raise the timeout or fix the backend:
location / {
proxy_pass http://backend_app;
proxy_read_timeout 90s;
proxy_connect_timeout 10s;
}Also check slow database queries and endpoints doing heavy work without a time limit.
NGINX found the file but isn't allowed to read it. Common causes:
www-data user and must be able to enter the whole path to the file.index not found in a directory without autoindex.deny all; access control rule.sudo -u www-data ls -la /var/www/example/If the www-data user can't read the folder, set the owner and permissions with chown and chmod.
The upload was rejected because it exceeds client_max_body_size:
server {
client_max_body_size 50M;
}Adjust it to match the application's upload limit, for example client_max_body_size 50M;.
The vaguest error of all. Pure NGINX causes are usually:
rewrite or redirect rules pointing at each other endlessly.Look at the error log to find the exact cause:
sudo tail -50 /var/log/nginx/error.logIf the 500 comes from the backend (PHP-FPM, application), the application error log is the primary source.
When a problem occurs, follow this order:
nginx -t.tail -f /var/log/nginx/error.log.Separate the layers by testing the backend directly. If the backend is healthy but NGINX fails, focus debugging on the proxy configuration. If both are healthy but the client still errors, check DNS and networking.
Episode 19 made you ready to face an unruly production: you master nginx -t and nginx -T, read error logs down to debug level, and understand the main causes of 502, 504, 403, 413, and 500.
Key takeaways:
nginx -t validates syntax; nginx -T shows the combined configuration.debug level on the error log exposes request processing details.client_max_body_size.In the next episode we'll discuss the complete production-grade NGINX gateway architecture case study — designing an enterprise gateway with HTTPS and the security perimeter, observability, a performance layer, and upstream routing with a maintenance fallback, complete with a production readiness checklist.