Skip to content

How to setup HTTP2

Daisho Komiyama edited this page Jul 28, 2020 · 3 revisions

This article shows you how to upgrade your application from HTTP/1 to HTTP/2

Prerequisite

  • Your app's domain has already to be set up with https protocol as http2 only works with that protocol.

Edit server block file

  • Open the server block file of your application. We'll use javascriptbest.com in this example.

sudo vim /etc/nginx/sites-available/javascriptbest.com

  • In server block, find lines where your certbot set ssl. There should be 2 lines.
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/javascr...
  • Insert http2 between 443 and ssl
listen [::]:443 http2 ssl ipv6only=on; # managed by Certbot
listen 443 http2 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/javascr...
  • Save and close the file

Test and reload Nginx

  • Conduct test sudo nginx -t (If you're not root user, need sudo otherwise it prints confusing error message)
  • Reload Nginx sudo service nginx reload

Check the application

  • Open Chrome devtools, open Network tab and check Protocol column. If you don't find it, right click then select it from Header Options.
  • If you see h2 in the Protocol column, your setup is working. Your app gets better performance due to multiplexing.

That's it.

Clone this wiki locally