Diagnosis of 403 and 404
Start with the selected server and location
A 403 means the request was refused; a 404 means the target was not found or the server chooses not to disclose it. Neither proves which component generated the response. First record the intended hostname, path, method and status, then check whether the intended virtual server and location handled it. A correct file in the wrong document root will still be missing. This local command fixes the host and captures response headers; use the lab listener only.
curl --max-time 3 -i -H "Host: shop.test" http://127.0.0.1:19447/catalog.txtTrace the URI to a file
With root, Nginx appends the URI path to the configured directory. In this partial server configuration /catalog.txt maps to site/catalog.txt under the fixture prefix. A directory existing does not imply its index exists; with autoindex off a request for a directory without an index can return 403. A missing file normally returns 404. Read the selected path in the error log and compare it with the intended file. Do not solve missing-file errors with broad permissions.
root site;index index.html;location / { try_files $uri $uri/ =404; }Distinguish policy denial from file permission
A rule can deny access even when the file is readable. A worker also needs search permission on each parent directory and access to the actual file; discretionary permissions and SELinux/AppArmor can independently matter. A synthetic error indicating permission denied suggests an access check, not a missing file. In the lab, the private location is intentionally denied. Keep it denied; investigate the reason before changing a policy.
location = /private.txt { deny all; }location = /catalog.txt { try_files $uri =404; }Use discriminating checks for other client errors
Compare the Content-Type of a known CSS file with its expected media type; check types configuration rather than renaming files blindly. For redirects, inspect Location and verify the host and scheme before following. A 413 can reflect a body limit; a 414 can reflect a request target too long. Large header behavior depends on the receiver: Nginx can return 400 for an oversized individual request header, while other components may use 431. Check which hop rejected the request and its documented limit; do not raise all limits globally. This synthetic table is evidence to classify, not actual output.
403 /private.txt policy denial expected404 /missing.txt no fixture file403 /empty/ no index; listing disabled200 /style.css expected text/cssCheck Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Diagnosis of 403 and 404
Diagnose Nginx 403 and 404 responses by tracing server selection, URI mapping, access policies and file permissions with targeted checks.
A file exists under site/catalog.txt but a request selects another virtual server. What should you check first?
An empty directory has no index and listing is disabled. What outcome is plausible?
A readable file is in a location with deny all. What should you do?
Which check best diagnoses CSS served with the wrong media type?
A large header receives 400 from Nginx. Is that impossible because 431 exists?