nginx: [emerg] unknown directive 🖥️ Nginx / Apache

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

  1. Run sudo nginx -t and check the reported line and the one before
  2. Install/load the module (load_module)
  3. Translate Apache rules to Nginx equivalents

Detailed fix by platform

Shell

  1. nginx
    sudo nginx -t
    sudo nginx -V 2>&1 | tr ' ' '
    ' | grep module

How to diagnose

  1. Line — Reported line and the previous one
  2. 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.