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.,
servernameinstead ofserver_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_passrequiresngx_http_proxy_module). - A dynamic module was not loaded with
load_modulein the main context. - The directive is placed in the wrong context (e.g.,
server_nameinsidehttpblock instead ofserverblock).
How to Fix It
1. Find the exact line with the error
sudo nginx -tNginx 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 line3. 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 modules5. Load a dynamic module
load_module /usr/lib/nginx/modules/ngx_http_geoip_module.so;FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro