Requesting help with HTTP2 configuration in default.conf

# nginx -v
nginx version: nginx/1.24.0 (Ubuntu)

# ls /etc/nginx/sites-enabled/
default.conf xxx1.conf xxx2.conf

When adding http2 to all the listen lines in the three conf files, default.conf looks like this:

listen 80 http2 default_server;
listen [::]:80 http2 default_server;
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name _;

The difference between default.conf and xxx1.conf / xxx2.conf is that the latter two have specified domain names for server_name, but do not have default_server.

After successfully running sudo nginx -t && sudo nginx -s reload, visiting the domains for xxx1.conf and xxx2.conf works fine. However, when using http://ip or http://{unspecified domain}, the browser does not open the homepage but instead downloads a file named with no extension and only 57 bytes in size.

If you modify default.conf to remove http2 from the listen lines, while keeping http2 in the listen lines of xxx1.conf / xxx2.conf, after running sudo nginx -t && sudo nginx -s reload successfully, visiting the domains for xxx1.conf and xxx2.conf works fine, and using http://ip or http://{unspecified domain} also works correctly and opens the homepage.

However, sudo nginx -t && sudo nginx -s reload will show warning messages:

2025/11/13 22:11:27 [warn] 250001#250001: protocol options redefined for 0.0.0.0:80 in /etc/nginx/sites-enabled/xxx2.conf:2
2025/11/13 22:11:27 [warn] 250001#250001: protocol options redefined for 0.0.0.0:443 in /etc/nginx/sites-enabled/xxx2.conf:8
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
2025/11/13 22:11:27 [warn] 250004#250004: protocol options redefined for 0.0.0.0:80 in /etc/nginx/sites-enabled/xxx2.conf:2
2025/11/13 22:11:27 [warn] 250004#250004: protocol options redefined for 0.0.0.0:443 in /etc/nginx/sites-enabled/xxx2.conf:8
2025/11/13 22:11:27 [notice] 250004#250004: signal process started

How should the configuration be set so that accessing http://ip or http://{unspecified domain} works correctly, and sudo nginx -s reload does not show any warning messages?

This is a harmless warning because you’re redefining the same listen port.
The http2 parameter of the listen directive was deprecated with 1.25.1/1.26.0 in favor of the http2 directive.

Upgrading and migrating to the http2 directive will remove the warnings.

2 Likes

Thank you

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.