So far Google is encouraging all web sites to be served over HTTPS, and if you also use HTTP2 protocol, you will increase your site's security and at the same time fast page loading which will translate in better page ranking. If you are using Nginx web server, which i strongly recommend, just follow these simple steps to get up and running in HTTP2.


Install Nginx

Ensure that Nginx is installed on your server. The process for installing Nginx may vary depending on your operating system. Here's an example command for installing Nginx on Ubuntu

sudo apt-get update
sudo apt-get install nginx


Configure SSL

HTTP/2 requires the use of SSL/TLS encryption. So, you need to configure SSL for your Nginx server. Obtain an SSL certificate from a trusted certificate authority (CA) or use a self-signed certificate for testing purposes. You will need the certificate file and private key.

Create a new Nginx server block or modify the existing one to include the SSL configuration. Open the Nginx configuration file (nginx.conf or a file in the /etc/nginx/conf.d/ directory) and add or modify the following lines:

server {
    listen 443 ssl http2;

    ssl_certificate /path/to/your_certificate.crt;
    ssl_certificate_key /path/to/your_private_key.key;

    # Other SSL configuration options

    # Other server configuration directives

Ensure that you replace, /path/to/your_certificate.crt, and /path/to/your_private_key.key with the appropriate values for your setup.


Enable HTTP/2

To enable HTTP/2, you need to add the http2 parameter to the listen directive in the Nginx server block. As shown in the previous step, the line listen 443 ssl http2; specifies that the server should listen on port 443 using SSL and enable HTTP/2.



Configure Additional Nginx Settings: You can further customize your Nginx configuration to optimize it for HTTP/2. Some recommended settings include:

Enable gzip compression

Add the following lines inside the server block to enable gzip compression:

gzip on;
gzip_types text/plain text/css application/javascript application/json;


Adjust keepalive timeout

Set the keepalive timeout value to a higher value to allow persistent connections and reduce connection overhead. Add the following line inside the server block:

keepalive_timeout 60s;


Enable server push

If you want to take advantage of server push, you need to add appropriate configuration directives to your Nginx server block. Server push configuration depends on your specific application and the resources you want to push.

Consult the Nginx documentation for more information on configuring server push.