How to Enable HTTP/2.0 in Nginx on CentOS

Enable HTTP/2.0 in Nginx on CentOS

In this article, we will have explained the necessary steps to install and configure Enable HTTP/2.0 in Nginx on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Nginx pronounced “engine x” is an open-source, high-performance HTTP and reverse proxy server responsible for handling the load of some of the largest sites on the Internet. It can be used as a standalone web server, load balancer, content cache, and reverse proxy for HTTP and non-HTTP servers. HTTP/2 is the latest standard for the HTTP protocol, it is the successor of HTTP/1.1. It is becoming increasingly popular due to the benefits it brings to web developers and users in general. It provides an optimized transport for HTTP semantics by supporting all the core features of HTTP/1.1 but aims to be more efficient in multiple ways.

Enable HTTP/2.0 in Nginx on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo dnf update

Step 2. Install Nginx on CentOS 8.

Now that the repository is added, it’s time to install Nginx:

sudo dnf install nginx

Once it is installed, start and enable the Nginx service by typing:

sudo systemctl start nginx
sudo systemctl enable nginx

To verify that the service is running, check its status:

sudo systemctl status nginx

Step 3. Configure Firewall.

If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Step 4. Enable HTTP/2.0 in Nginx on CentOS system.

First, we verify that Nginx was built with the ngx_http_v2_module module by running the following command:

$ /usr/sbin/nginx | grep _module | grep -v configure| sort | grep ngx_http_v2_module
invalid directive "%V": ngx_http_spdy_module was superseded by ngx_http_v2_module
invalid parameter "spdy": ngx_http_spdy_module was superseded by ngx_http_v2_module

Next, open your websites virtual server block (or virtual host):

nano /etc/nginx/conf.d/linuxtips.us.conf

Modify using nano and add http2 under listening directive:

server {
        listen       443 http2 ssl;
        …....
}

Once done, check the NGINX’s configuration syntax, if it’s OK, restart the Nginx service:

nginx -t
sudo systemctl restart nginx

That’s all you need to do to install Enable HTTP/2.0 in Nginx on CentOS 8. I hope you find this quick tip helpful. For further reading on Enable HTTP/2.0 in Nginx, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.

Tags: