Common causes
- The directive belongs to a module that is not compiled in or loaded, such as more_set_headers (headers-more), brotli or geoip2
- A typo or a missing semicolon on the previous line, so two directives run together
- Apache .htaccess syntax (RewriteEngine, RewriteRule) pasted into an Nginx config
- An invisible UTF-8 BOM or non-breaking space at the start of the file or line, shown as odd characters in the quoted name
- A directive from a newer Nginx version than the one installed (for example http2 on; requires 1.25.1+)
- Commercial NGINX Plus-only directives used on open-source Nginx
How to fix it
- Run the config test. Run sudo nginx -t. It prints the unknown directive with its file and line number.
- Check spelling and the line above. Open the file at that line and check spelling, then make sure the previous directive ends with a semicolon and braces are balanced.
- Load the missing module. List modules with nginx -V 2>&1 | tr ' ' '\n' | grep module and ls /etc/nginx/modules-enabled/. Install the package (for example libnginx-mod-http-headers-more-filter on Debian/Ubuntu) or add load_module at the top of nginx.conf.
- Translate Apache rules. Replace RewriteRule and similar lines with Nginx equivalents such as try_files, return 301 or rewrite. Nginx never reads .htaccess syntax.
- Remove hidden characters. If the quoted name looks garbled, run file yourfile.conf and strip the BOM with sed -i '1s/^\xEF\xBB\xBF//' yourfile.conf, then retest.
- Check your Nginx version. Run nginx -v and compare it to the directive's documentation. Use the older equivalent or upgrade Nginx from the official repository.
Shell (diagnose and load a dynamic module)
sudo nginx -t
nginx -v
nginx -V 2>&1 | tr ' ' '\n' | grep -i module
ls /etc/nginx/modules-enabled/
# Debian/Ubuntu: install headers-more
sudo apt install libnginx-mod-http-headers-more-filter
sudo nginx -t && sudo systemctl reload nginx How to stop it happening again
- Always run nginx -t before reloading
- Keep configs in version control and lint them in CI
- Document required dynamic modules alongside the config