nginx: [emerg] unknown directive "http2"

Hi there,

I’m in the process in updating an older trellis project and I’m almost there, but somehow I can’t get past this unknown directive “http2” nginx error:

RUNNING HANDLER [common : reload nginx] ****************************************
fatal: [xxx.xx.xxx.xx]: FAILED! => {"changed": true, "cmd": ["nginx", "-t"], "delta": "0:00:00.016680", "end": "2024-10-23 17:01:06.837937", "msg": "non-zero return code", "rc": 1, "start": "2024-10-23 17:01:06.821257", "stderr": "nginx: [emerg] unknown directive \"http2\" in /etc/nginx/sites-enabled/example.nl.conf:7\nnginx: configuration file /etc/nginx/nginx.conf test failed", "stderr_lines": ["nginx: [emerg] unknown directive \"http2\" in /etc/nginx/sites-enabled/example.nl.conf:7", "nginx: configuration file /etc/nginx/nginx.conf test failed"], "stdout": "", "stdout_lines": []}

I updated trellis with the latest roles and I can see the nginx http2 & http3 directive are added in the wordpress-site.conf.j2 template here:

I also had to delete old apt-keys, like described here.

When I ssh into my production server, nginx -v outputs:

nginx version: nginx/1.19.7

I’m still on bento/ubuntu-20.04 since I don’t want to update my droplets.
What exactly determines the installed nginx version? Can’t seem to find it in the nginx role defaults?

Are the http2 & http3 directives only availble in the latest nginx version in bento/ubuntu-22.04?
As far as I understand the directives were added in nginx version 1.19.1, so it should be okay?

Thanks!

Trellis uses a dedicated PPA for nginx.

Ah ok so the directives were added in nginx 1.25.1, that makes sense.
But how can I upgrade my nginx version then?

Locally I didn’t get the nginx error so I checked the version and it’s:

nginx version: nginx/1.27.2

So how can I (manually) upgrade my nginx version on existing droplets?

:thinking: The nginx repository is used, and it should contain a recent enough version (1.26.2-1~focal) of the nginx package:
http://nginx.org/packages/ubuntu/dists/focal/nginx/binary-amd64/Packages

Package: nginx
Version: 1.26.2-1~focal
Architecture: amd64
Maintainer: NGINX Packaging <nginx-packaging@f5.com>
Installed-Size: 3482
Depends: libc6 (>= 2.28), libcrypt1 (>= 1:4.1.0), libpcre2-8-0 (>= 10.22), libssl1.1 (>= 1.1.1), zlib1g (>= 1:1.1.4), lsb-base (>= 3.0-6)
Recommends: logrotate
Conflicts: nginx-common, nginx-core
Replaces: nginx-common, nginx-core
Provides: httpd, nginx, nginx-r1.26.2
Filename: pool/nginx/n/nginx/nginx_1.26.2-1~focal_amd64.deb
Size: 1011888
MD5sum: da9e88c3cf273ee66028a471ce83912b
SHA1: 427e66e089c1081e683343f854af2ffdbb10bbff
SHA256: b0e350427d7fdee162ef5130cc1073529ab8a18e5d4647d79844d7624546abe7
Section: httpd
Priority: optional
Homepage: https://nginx.org
Description: high performance web server
 nginx [engine x] is an HTTP and reverse proxy server, as well as
 a mail proxy server.

An apt update && apt upgrade should find that most recent version.

What does dpkg -s nginx tell on the Trellis system, from where is the nginx package installed?

Yeah I just had to manually upgrade it on the remote server:

Version now outputs:

nginx version: nginx/1.27.2

And directives are ok now!

1 Like

Currently the nginx package is not locked to a specific version:
https://github.com/roots/trellis/blob/a5040add97ac2befc1325eb13c80ee8c96d15dc5/roles/nginx/tasks/main.yml#L12-L16