Troubleshoot NGINX Config That Fails nginx -t Prompt
Diagnose and fix an NGINX configuration that fails `nginx -t` by reading the exact error/line, explaining the underlying cause, and returning a corrected, test-passing config with the change isolated.
- Target user
- DevOps engineers and sysadmins editing NGINX configs
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a senior NGINX engineer who debugs configuration failures. My config fails `nginx -t` (or reloads cleanly but behaves wrong) and I need it fixed without breaking the rest. I will provide: - The full `nginx -t` (or `nginx -T`) output, including the exact error message and `in /path:line` - The offending file/block (paste enough surrounding context, not just the flagged line) - The NGINX version and which modules are compiled in (relevant for "unknown directive") - What the config is supposed to do Your job: 1. **Read the error literally** — translate the `nginx -t` message (e.g. "unexpected }", "directive is not allowed here", "unknown directive", "duplicate location", "host not found in upstream") into its precise meaning. 2. **Locate the real cause** — the flagged line is often a symptom of an unclosed brace, a directive in the wrong context, a missing `;`, or a module that isn't loaded; find the actual source. 3. **Explain context rules** — if a directive is "not allowed here," state which context (main/http/server/location) it belongs in and why. 4. **Fix minimally** — return only the corrected block(s) with the change clearly marked, preserving formatting and unrelated directives. 5. **Catch related issues** — scan the surrounding config for the same class of mistake that will fail on the next reload. 6. **Verify safely** — give the `nginx -t` re-check, then `nginx -s reload` (not restart) so live connections drain. Output as: (a) plain-English error explanation, (b) root cause, (c) corrected block with the diff marked, (d) test + reload steps.
Related prompts
-
Configure NGINX TLS, HSTS & OCSP Stapling Prompt
Build a modern, A-grade NGINX TLS configuration with correct protocol/cipher selection, OCSP stapling, session settings, and a safe HSTS rollout, then verify it against a real handshake.
-
Fix NGINX Location Block Precedence Prompt
Untangle why the wrong NGINX location block is matching a request by tracing prefix vs regex vs exact-match precedence, then reorder/rewrite the blocks so each URL hits the intended handler.