Nginx: nginx: [emerg] unknown directive "x" in /etc/nginx/sites-enabled/x:12 — configuration file test failed
Nginx found a directive it doesn’t know — a typo, a missing semicolon on the previous line, a directive from a module that isn’t installed, or Apache syntax in an Nginx file.
Seen on:
Nginx
Meaning
Always run nginx -t before reload. Missing ; makes the next word look like a directive. Directives like more_set_headers, brotli, geoip2 need dynamic modules loaded.
Common causes
- Typo or missing semicolon on the previous line
- Module not installed/loaded (headers-more, brotli, geoip2)
- Apache/.htaccess syntax pasted into Nginx
- Hidden characters (BOM, smart quotes)
⚡ Quick fix
- Run sudo nginx -t and check the reported line and the one before
- Install/load the module (load_module)
- Translate Apache rules to Nginx equivalents
Detailed fix by platform
Shell
- nginx
sudo nginx -t sudo nginx -V 2>&1 | tr ' ' ' ' | grep module
How to diagnose
- Line — Reported line and the previous one
- Modules — nginx -V
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026