setup http2 in nginx

How To Enable HTTP2 in NGINX

HTTP/2 is a successor to HTTP/1.x and offers many advantages such as parallel processing, full multiplex, header compression, and even server push. It is important to set up HTTP2 in NGINX to improve website speed and performance. In this article, we will look at how to enable HTTP2 in NGINX.

How To Enable HTTP2 in NGINX

Here are the steps to enable HTTP2 in NGINX. Before proceeding, please ensure:

  1. You are using NGINX 1.9.5 or above. You can NGINX version with nginx -v command
  2. You have enabled HTTPS/SSL. Here are the steps to configure SSL in NGINX.

1. Open NGINX configuration file

Open terminal and run the following command to open NGINX configuration file.

$ sudo vi /etc/nginx/nginx.conf

If you have configured separate virtual hosts for your website (e.g, such as /etc/nginx/sites-enabled/example.conf then open its configuration with the following command

$ sudo vi /etc/nginx/sites-enabled/example.conf

Also read : How to Fix NGINX 413 Request too large error

2. Setup HTTP/2

If you have enabled SSL in NGINX, you will already have the following line in your server configuration.

listen 443 ssl;

Change it to the following to enable HTTP/2

listen 443 ssl http2;

Your HTTPS server block will look something like

server { 
    listen 443 ssl http2; 
    ssl_certificate ...
    ssl_certificate_key ...

Also read : How to Remove WWW from Domain URL in NGINX

3. Restart NGINX Server

Finally, run the following command to check syntax of your updated config file.

$ sudo nginx -t

If there are no errors, run the following command to restart NGINX server.

$ sudo service nginx reload #debian/ubuntu
$ systemctl restart nginx #redhat/centos

4. Verify HTTP/2

Use a third party tools like KeyCDN HTTP2 checker that allow you to check if HTTP/2 is enabled on your website.

After you enter your website, with HTTPS URL, it will tell you if HTTP/2 is enabled in it or not.

As you can see, it is quite easy to enable HTTP/2 in NGINX.

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it today!


About Ubiq

Ubiq is a powerful dashboard & reporting platform for small & medium businesses. Build dashboards, charts & reports for your business in minutes. Get insights from data quickly. Try it for free today!