Nginx Warning http2 directive is deprecated

After upgrade to the nginx 1.26 on Debian 12, sudo nginx -t throw some warning issue in the nginx config

$ sudo nginx -t
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enable/atetux.conf:7

for now that not a issue, just a warning. But it’s better to fix it right know because it only take few minutes, because the warning error cause some noise in the logs and might throw error in the later version, which make nginx unable to start.

The solution for the issue is to remove http2 line listen and create a new line with http2 on;. Lets take this simple sample as example

server {
    listen 443 ssl http2;

replace with

server {
    listen 443 ssl;
    http2 on;

after update the nginx config file, validate the config

sudo nginx -t
# output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

if there’s no error reload the nginx to apply the changes

sudo systemctl reload nginx

Leave a Comment