Nginx Troubleshooting: A First Diagnostic Workflow
Start with evidence, not a restart
When a page fails, reproduce the smallest request that demonstrates the problem. Record the expected status and body marker, then compare the actual response. A syntax test checks configuration and referenced resources, not the response a client will receive. Use this sequence only inside an approved non-root disposable lab.
nginx -p "$PWD/" -c nginx.conf -t# Confirm the configured loopback port belongs to the lab before requesting it.ss -ltn "sport = :18111"If syntax validation fails, read the reported file and line before changing anything. If there is no listener, inspect the lab process and startup error log; if a different process owns the port, stop the experiment rather than killing it. A listening socket alone does not prove you reached the correct virtual server.
curl --noproxy '*' --max-time 3 -i -H 'Host: learn.test' http://127.0.0.1:18111/guide.htmltail -n 10 logs/access.jsonltail -n 10 logs/error.logA 200 with a wrong body may be a wrong server or location. Compare the logged selected site and processed URI with your expected route. A 404 may be an explicit return, a missing file or the wrong root. Inspect only lab-owned files. Do not dump a real production configuration or logs into a public chat.
Separate three similar-looking failures
A: status=404 site=default.test uri=/guide.htmlB: status=404 site=learn.test uri=/missing.html; open() ... No such file or directoryC: status=403 site=learn.test uri=/restricted.html; open() ... Permission deniedA suggests server selection; inspect the Host and default listener. B suggests a filesystem mapping or missing file; inspect root and the intended public directory. C suggests worker access; check the worker identity and traversal/read permissions on the relevant path. A 403 alone does not establish a permissions problem. These are hypotheses supported by the extra evidence, not rules based only on status.
ls -ld site site/guide.html# Compare with the root directive in the selected server.A worker must be able to traverse the parent directories and read the intended public file. Make a narrow ownership or permission correction only after reviewing the intended policy. Never use chmod 777, run workers as root, or disable a security control as a generic diagnostic shortcut.
Check upstream failures and verify fixes
client_status=502 upstream_status=502[error] connect() failed (111: Connection refused) while connecting to upstreamThis points toward backend connectivity or availability; inspect the expected local backend listener and address with its owner. A 502 or 504 alone is not a complete diagnosis. In the actual chapter lab no backend is launched; the example is an offline case for the next chapter.
nginx -p "$PWD/" -c nginx.conf -t && nginx -p "$PWD/" -c nginx.conf -s reloadRun only for your own active lab master after verifying the PID and prefix. A successful signal command is not proof the new configuration took effect. Repeat the original request and compare status, body and access record; test a neighboring route for regression. If the correction fails, restore the reviewed lab configuration, test and reload again. Document observations, not just commands.
Practice
Use the three offline incident cases plus the optional local lab. For each, record evidence, a leading hypothesis, one read-only next check and the observable result that would confirm a fix.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Troubleshooting decisions
Choose the best answer based on the lesson and synthetic evidence.
A syntax test succeeds but the page is wrong. What next?
A 404 record names default.test instead of learn.test. Which check first?
A diagnostic says Permission denied on the intended file. What check is appropriate?
A 502 diagnostic says connection refused. What is the next hypothesis to check?
What verifies a lab reload correction?