Nginx: fixing 'http2 directive is deprecated'
Intro
Lately I’ve rarely checked the version updates on my VPS stacks. Well, when wanted to add some a new vhost
to my Nginx, a lengthy validation message appeared with many [warn]
outputs when I ran nginx -t
. So that’s make me feel attacked what happen with my Nginx 👀.
Just googled and found that since Nginx version 1.25.1 there is Important changes and it mention deprecation of listen ... http2
directive.
Sources:
But, like in the early of this words, personally Im not sure when it was updated 🤷, because I was used stable Nginx packages from nginx upstream (adding via /etc/apt/sources.list.d
).
Dig in
Alrite, let’s have fun with shell right now, so just analyze with…
# ls to sort by date
$ ls -alsht /var/log/apt/
# zcat history one by one; why not
$ zcat /var/log/apt/history.log.2.gz | grep nginx
Upgrade: nginx:amd64 (1.24.0-1~jammy, 1.26.0-1~jammy)...
# ok, lets see the term.log.2.gz and found it!
$ zcat /var/log/apt/term.log.2.gz | grep nginx
Preparing to unpack .../11-nginx_1.26.0-1~jammy_amd64.deb ...
Unpacking nginx (1.26.0-1~jammy) over (1.24.0-1~jammy) ...
Setting up nginx (1.26.0-1~jammy) ...
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/xxxxx:6
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/xxxxx:22
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/xxxxx:53
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/xxxxx:29
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/xxxxx:30
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/xxxxx:3
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/xxxxx:3
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/xxxxx:3
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/xxxxx:55
So we got that it jumped from versio 1.24.xx
to 1.26.xx
. It was expected because stable upstream release from Nginx was using even minior version. Can check it here
.
Fixing time
To fix it, just swap the directive sections of http2
. Here is the comparison.
- Before version
1.25.xx
.
server {
listen 443 ssl http2;
...
}
- After version
1.25.xx
.
server {
listen 443 ssl;
http2 on;
...
}
That’s all for my quick writing about fixing http2
directive deprecated on Nginx story.
Thank You!.