nginx, http,

How to enable HTTP/2 in Nginx

Jan 18, 2022 · 1 min read · Post a comment

HTTP/2 was published almost 7 years ago, HTTP/3 being an internet draft standard since October 2020, and yet here we are, most of us still using HTTP/1.1. Considering how things quickly change in the IT world, I’ll give it av few (5-7) more years for the full migration to take place. Therefore, I’m going to show you how easily you could enable HTTP/2 on Nginx.

Prerequisites

  • Nginx
  • sudo privileges

Solution

Step 1. Open your virtual host file usually found under /etc/nginx/conf.d/ dir, find and edit listen 443 line.

listen 443 ssl http2;

Note(s): Notice the http2 parameter.

Step 2. Check the Nginx configuration syntax.

nginx -t

Step 3. Restart Nginx service.

systemctl restart nginx

Step 4. Verify that HTTP/2 is enabled.

curl -Iks https://devcoops.com

Expected output:

HTTP/2 200 

Conclusion

Few key points to consider before transitioning from HTTP/1.1 to HTTP/2:

  • HTTP/2 works over HTTPS only.
  • TLS 1.2 or later is required.

On a side note, follow our official channel on Telegram.