Skip to content
nginx: [emerg] unknown directive 'xyz'

nginx: [emerg] unknown directive 'xyz'

DodaTech 2 min read

The error “nginx: [emerg] unknown directive ‘xyz’” means Nginx encountered a configuration directive it does not recognize. The parser stops immediately and Nginx fails to start.

What It Means

Nginx parses its configuration files (typically in /etc/nginx/) sequentially. When it reads a line that starts with a word it does not recognize as a valid directive, it raises an unknown directive error and exits. This is a fatal configuration error — Nginx will not start until it is fixed.

Why It Happens

  • There is a typo in a directive name (e.g., servername instead of server_name).
  • A directive is missing its terminating semicolon, causing the next line to be parsed as part of the directive name.
  • A required Nginx module is not compiled or loaded (e.g., proxy_pass requires ngx_http_proxy_module).
  • A dynamic module was not loaded with load_module in the main context.
  • The directive is placed in the wrong context (e.g., server_name inside http block instead of server block).

How to Fix It

1. Find the exact line with the error

sudo nginx -t

Nginx reports the file path, line number, and the unknown directive.

2. Check for missing semicolons

Each directive line must end with ;:

server_name example.com;  # correct
server_name example.com   # missing ;  error on next line

3. Verify the directive spelling

# Correct
server_name example.com;
root /var/www/html;
proxy_pass http://backend;

# Incorrect
servername example.com;
rote /var/www/html;
proxy_pass: http://backend;

4. Install the missing module

sudo apt install nginx-extras  # includes many additional modules

5. Load a dynamic module

load_module /usr/lib/nginx/modules/ngx_http_geoip_module.so;

FAQ

How do I list all compiled-in Nginx modules?
Run nginx -V 2>&1 | grep -- '--with-'. This shows all modules included at compile time. Modules not listed must be loaded dynamically or installed separately.
What is a directive context in Nginx?
Nginx has block contexts: events, http, server, location, if, upstream, etc. Each directive is valid only in specific contexts. For example, server_name is valid inside server but not inside location. Refer to the Nginx documentation for each directive’s valid contexts.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro