How to get rid of the Nginx message: "listen ... http2" directive is deprecated
If you have updated Nginx to a version greater than or equal to 1.25.1, you may run into this message, nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in ..... This blog post will show you how to get rid of it.
Nginx version 1.25.1 and above
In Nginx versions 1.25.1 and above, Nginx updated its HTTP module ngx_http_core_module by removing deprecating the additional http2
parameter in the listen
directive. There is a new http2
directive from the module ngx_http_v2_module that provides support for HTTP/2 and will have to be used instead of using the listen
directive with the http2
parameter on the same line.
In your nginx.conf
file or similar virtual host file, you probably have an entry like this:
listen 443 ssl http2;
The http2
directive enables HTTP/2 on a per-server basis.
If you do have this listen 443 ssl http2
directive in one line, you will have to change it when you update your Nginx version to 1.25.1 or above.
The latest version of Nginx is 1.27. You can check your Nginx version with nginx -version
. This is what I have in both my webhost and Mac.
$ sudo nginx -version
nginx version: nginx/1.27.0
Nginx logs showing the "listen ... http2" directive is deprecated message
I found several instances of this in all my logs since I host many websites.
If you are not sure where to see this, run nginx -t
and you'll probably see them on your screen.
$ sudo nginx -t
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/conf.d/ABC.conf:250
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/conf.d/DEF.conf:250
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/conf.d/PQR.conf:250
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/conf.d/XYZ.conf:250
Find all conf files with the listen directive
To find all conf files with the listen - ssl - http2 directive, run this:
grep -R /etc/nginx/ -e 443 |grep -v http2
grep -R /etc/nginx/ -e 443 |grep -v ssl
Solution to fix this deprecation warning
When you check your Nginx logs and see this message, all you have to do is change this:
listen 443 ssl http2;
to:
listen 443 ssl;
http2 on;
Do it for every instance of listen 443 ssl http2
that you see in each conf file.
Test with nginx -t
Run this command:
sudo nginx -t
You should not see the above deprecation warning anymore.
However, you may see a new warning similar to this:
nginx: [warn] protocol options redefined for 0.0.0.0:443 in /etc/nginx/conf.d/XXX.conf:13
nginx: [warn] protocol options redefined for 0.0.0.0:443
I did get several warnings similar to this:
nginx: [warn] protocol options redefined for 0.0.0.0:443 in /etc/nginx/conf.d/ABC.conf:23
This was because my listen directives were not consistent across the board. I host about a dozen websites, and this change required me to update all the corresponding virtual host conf files correctly.
If you get that above warning, that solution is to open each conf file and make sure that you have these two lines in place.
listen 443 ssl;
http2 on;
If you are hosting multiple websites on Nginx, you will have a lot of editing to do.
If you have this:
listen 443 default_server;
Change it to:
listen 443 default_server ssl;
If you have this:
listen [::]:443 default_server;
Change it to:
listen [::]:443 default_server ssl;
If you have this:
listen 443 ssl;
Add the line http2 on
after it:
listen 443 ssl;
http2 on;
Conclusion
If this worked for you or did not work for you, do let me know. Thanks.
Related Posts
If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.