nginx.ccWeb server troubleshooting desk
Home / Errors / emerg
emerg

nginx unknown directive: http2, brotli, quic and more

Short answer

nginx -t reporting “unknown directive "http2"” and the like means this nginx does not know the directive: the version is too old (http2 on needs 1.25.1+), the module is not built in or not loaded (brotli and headers-more are third-party), or it is a typo or an invisible character. Check nginx -V, then change the syntax or install the module.

Most common cause: The distro nginx is too old: Debian 12 ships 1.22, Ubuntu 24.04 ships 1.24, neither has http2 on;.

Try this first: HTTP/2 on older versions

# nginx < 1.25.1
listen 443 ssl http2;
# nginx ≥ 1.25.1
listen 443 ssl;
http2 on;

Last verified: · against the official docs listed below · Sources

Typical log lines

nginx: [emerg] unknown directive "http2" in /etc/nginx/sites-enabled/example.conf:4
nginx: [emerg] unknown directive "brotli" in /etc/nginx/nginx.conf:30
nginx: [emerg] unknown directive "more_set_headers" in /etc/nginx/conf.d/security.conf:2

Common causes

  1. The distro nginx is too old: Debian 12 ships 1.22, Ubuntu 24.04 ships 1.24, neither has http2 on;.
  2. Third-party modules (brotli, more_set_headers) are not installed or load_module is missing.
  3. listen … quic needs nginx 1.25.0+ built with --with-http_v3_module.
  4. Config copied from a web page carries full-width spaces, zero-width characters or CJK punctuation.

Diagnosis commands

Version and built-in modules
#nginx -V 2>&1 | tr ' ' '\n' | grep -E 'version|http_v2|http_v3|brotli|headers-more'
Loadable dynamic modules
#ls /etc/nginx/modules-enabled/ /usr/lib/nginx/modules/ 2>/dev/null
Find non-ASCII characters
#grep -nP '[^\x00-\x7F]' /etc/nginx/sites-enabled/example.conf

Fix configs

HTTP/2 on older versions

# nginx < 1.25.1
listen 443 ssl http2;
# nginx ≥ 1.25.1
listen 443 ssl;
http2 on;

Install the brotli module on Debian 12+

apt install libnginx-mod-http-brotli-filter libnginx-mod-http-brotli-static
nginx -t && systemctl reload nginx

Or switch to a current nginx.org build

curl -fsSL nginx.cc/install | sudo bash -s -- --dry-run

Run nginx -t first, then systemctl reload nginx.

Key facts and sources

  • The http2 directive appeared in nginx 1.25.1. [nginx.org]
  • The HTTP/3 module is available since 1.25.0 and is not built by default; it needs --with-http_v3_module. [nginx.org]

Checked against the linked pages on 2026-11-14; the official docs win if a newer nginx changes them.

FAQ

Is “directive is not allowed here” the same thing?

No. It means the directive exists but sits in the wrong block (e.g. server_names_hash_bucket_size inside server); check the Context line in the docs.

Do nginx.org packages include brotli?

brotli is not an nginx module; it needs a third-party module package or a custom build. Debian ships libnginx-mod-http-brotli-filter since Debian 12.

Fix it with a tool

Related errors

Sponsored slot (empty)
VPS / CDN recommendations may appear here later, labelled as affiliate links. There are no referral links today.