How to Enable HTTP/2 in NGINX Web Server?
HTTP/2 is the fourth and most advanced version of HTTP. It is an ideal pick if you are inclined towards implementing the HTTP2 NGINX combination. HTTP2 is a protocol that is best for a resource-intensive website. Moreover, using the NGINX server acts as a cherry on the cake.
In today’s world, every business is trying to capture user attention via powerful and immersive content. The use of NGINX HTTP2 Proxy combination is imperative. How can you do it? Let’s read ahead and find out!
What is NGINX?
NGINX is an exceptional web and reverse proxy server with remarkable features compared to its competitor, Apache.
Despite a tough knock between the two, NGINX has officially overtaken Apache. As per stats, NGINX is used by 34% of the websites, whereas Apache is used by 33.1%.
NGINX is a great choice individually, but if you compare it with Apache, there are many benefits!
- It handles static content requests better than Apache and can serve more clients at the same time.
- It is a better solution for caching, load balancing, and reverse proxying.
Here are Some Details of NGINX Features:
- Load balancing: One of the key USPs of NGINX is load balancing. The load balancing feature of the NGINX server ensures that all the traffic to the website is handled well. It does this by distributing the request to multiple servers. The website should have multiple servers on the back end.
- Reverse Proxy: If the site has one server, it is wise to use a reverse proxy. A reverse proxy ensures that all the server requests go through it first. It receives the client’s request and forwards it to the appropriate server. Reverse proxy empowers the website with performance, scalability, and security.
- Caching: Caching data helps servers provide content faster, but it also overloads the server sometimes. Hence, the NGINX server caches the data, but only for a limited time. This directly boosts the speed of content delivery and reduces server overload.
Other than these, the NGINX server has features like IPV6 support, web sockets, URL rewriting, and auto-indexing.
How to Enable the HTTP2 NGINX Combination in a Web Server?
Once you understand HTTP2 and NGINX, the enabling process becomes easy. To implement the HTTP2 NGINX combo, keep in mind these prerequisites!
- Make sure you have HTTPS enabled on the server. Browsers permit HTTP2 only over HTTPS.
- Make sure that the installed NGINX version is 1.9.5 or more. HTTP2 is supported by NGINX version 1.9.5 and above.
Steps to Enable the NGINX HTTP 2 Combination!
Open the configuration file for NGINX:
Run the following command in the terminal to open the NGINX configuration file.
sudo vi /etc/nginx/nginx.conf
If the virtual host (/etc/nginx/sites-enabled/alpha.conf) for your website (e.g. www.alpha.com), the command will be
sudo vi /etc/nginx/sites-enabled/alpha.conf
Setup HTTP2:
You will see the following code in an SSL-enabled server.
listen 443 ssl;
You must change it to listen 443 ssl http2; to enable HTTP2!
The server block will be like this!
server {
listen 443 ssl http2;
ssl_certificate …
ssl_certificate_key …
}
Restart the NGINX Server:
Before you restart the server, you must verify the syntax of the configuration file you just updated. Run sudo nginx -t command to do that.
After this, enter the following command to restart the NGINX server.
sudo service nginx reload #debian/ubuntu
$ systemctl restart nginx #redhat/centos
Verify HTTP2:
After the last step, you can use any third-party tool online to check if HTTP2 is enabled or not. When you enter the HTTPS website URL, the tool will tell you whether HTTP2 is enabled on the server.
Conclusion
In the wrap-up, we can say that the process of NGINX Enable HTTP2 is pretty easy. Moreover, the need to enable HTTP2 is also critical if the website is resource intensive.
To ensure that the implementation of the HTTP2 NGINX combination is stress-free, make sure that the SSL certificate is installed on the NGINX web server.