Search code examples
nginxnginx-reverse-proxynginx-config

Nginx v1.25.1 http2 on; new recommendation creating another warn


Here is my website conf (using nginx v1.25.1):

# Redirect to https
server {
    listen 80;
    server_name domain.name www.domain.name;
    
    location ^~ /.well-known/acme-challenge/ {
        root /acme-challenge; # Make sure this path is correct
        allow all;
    }

    location / {
        return 301 https://www.domain.name/$request_uri;
    }
}

# Redirect from HTTPS non-www to HTTPS www
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;
    server_name domain.name;

    # SSL configuration
    ssl_certificate     /ssl/live/domain.name/fullchain.pem;
    ssl_certificate_key /ssl/live/domain.name/privkey.pem;

    location ^~ /.well-known/acme-challenge/ {
        root /acme-challenge; # Make sure this path is correct
        allow all;
    }

    location / {
        return 301 https://www.domain.name/$request_uri;
    }
}

# Redirect to the specific path
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;
    server_name www.domain.name;

    # SSL configuration
    ssl_certificate     /ssl/live/domain.name/fullchain.pem;
    ssl_certificate_key /ssl/live/domain.name/privkey.pem;

    location ^~ /.well-known/acme-challenge/ {
        root /acme-challenge; # Make sure this path is correct
        allow all;
    }

    location / {
        return 301 https://www.other.domain.name/app/;
    }

}

I use to use listen 443 ssl hhtp2; but I got these warnings:

nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/domain.name:14
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/domain.name:30

Then I searched and found this: https://www.nginx.com/blog/nginx-plus-r30-released/

Which tells us this:

Change this:

listen 443 ssl http2;

To this:

listen 443 ssl;
http2 on;

But now I have this warning:

nginx: [warn] protocol options redefined for 0.0.0.0:443 in /etc/nginx/sites-enabled/domain.name:20

I think it's not a big deal but I'd like to remove all warnings and I found nothing with Google or ChatGPT.


Solution

  • When I rewrite the configuration files of each website one by one, I also encounter the error message: "protocol options redefined"

    But when I changed all my websites to "http2 on;", the error message disappeared

    So there may be other places where the setting is still "listen 443 ssl http2;", and the number of lines pointed to by the error message may not necessarily be problematic.