Tutorial

How to Enable HTTP/2 NGINX for WordPress Website

HTTP/2 is a new version of the Hypertext Transport Protocol, which is used on the Web to deliver pages from server to browser. It is the first major update of HTTP in almost two decades, introduced to overcome the limitations of HTTP 1.1. The previous version of HTTP downloaded parts of a page in a queue, limiting the potential transfer speeds for most modern websites. An average modern webpage requires about 100 requests to be downloaded, each request being a picture, js file, css file, etc.

Enable HTTP/2 in Bitnami NGINX
Enable http2 in Bitnami NGINX.

How HTTP/2 boost the speed of a website or blog?

HTTP/2 brings a few fundamental changes to solve these problems:

  • All requests are downloaded in parallel, not in a queue.
  • HTTP headers are compressed.
  • Pages transfer as a binary, not as a text file, which is more efficient.
  • Servers can “push” data even without the user’s request, which improves speed for users with high latency.
  • Although HTTP/2 does not require encryption, developers of two most popular browsers, Google Chrome and Mozilla Firefox, stated that for security reasons they will support HTTP/2 only for HTTPS connections.

The HTTP/2 is a lot faster than that of HTTP1.1. So it would be best if you considered enabling the HTTP/2 feature.

How to Enable HTTP/2 in Ubuntu?

Open the configuration file for your domain.

You need to edit the Nginx configuration file for your domain. This file is typically located in the /etc/nginx/sites-available/ directory. You can open this file using a text editor such as nano. Replace your_domain with your actual domain name.

sudo nano /etc/nginx/sites-available/your_domain

Locate the listen variables associated with port 443

In the configuration file, you need to find the lines that start with listen and are associated with port 443. These lines tell Nginx to listen for incoming connections on port 443, which is the standard port for HTTPS connections.

listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
  1. Modify each listen directive to include http2: listen [::]:443 ssl http2 ipv6only=on; and listen 443 ssl http2;
  2. Save the configuration file and exit the text editor.

Modify each listen directive to include http2

To enable HTTP/2, you need to add http2 to each listen directive. This tells Nginx to use the HTTP/2 protocol when serving your site to browsers that support it.

listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
http2 on;

Save the configuration file and exit the text editor

After making these changes, save the configuration file and exit the text editor. If you’re using nano, you can do this by pressing Ctrl+X to exit, then Y to confirm that you want to save the changes, and finally Enter to confirm the file name.

Enable HTTP/2 in Bitnami NGINX

You can enable HTTP/2 just by editing bitnami.conf file of your bitnami WordPress nginx stack. To do this, you’ve to execute the following command.

sudo -i

And now move to the directory using.

cd /opt/bitnami/nginx/conf/server_blocks

Make a backup of the nginx.conf file

Before making any changes to your configuration files, creating a backup is a good practice. If something goes wrong, you can easily revert to the previous configuration. The nginx.conf file is usually located in the /etc/nginx/ directory. You can create a backup using the cp command:

scp wordpress-https-server-block.conf wordpress-https-server-block.conf.backup

You have to locate the configuration file for your website in the Bitnami NGINX stack. Now select the file using nano.

nano wordpress-https-server-block.conf

Now the .conf file will open up. You have to add http2 in the 443 server connection block, as displayed below.

server {
        listen 443 ssl;
        listen [::]:443 ssl ipv6only=on;
        http2 on;
        server_name  localhost;
        ssl_certificate      server.crt;
        ssl_certificate_key  server.key;
        ssl_certificate      
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_session_tickets off;
        ssl_stapling on;
        ssl_stapling_verify on;
        ssl_ciphers  HIGH:!aNULL:!MD5;
#       ssl_prefer_server_ciphers  on;
#       include "/opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf";
       include "/opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf";
    }

Save the settings by pressing ctrl+X, then Y, and then press enter to update the changes.

Now you can check that all NGINX configurations you made are correct using the following command line.

nginx -t

Reload server

nginx -s reload

To restart Bitnami nginx run the following command line.

sudo /opt/bitnami/ctlscript.sh restart nginx

After the restart, you can check the HTTP/2 status of your website, which will result as enabled. Improve server security by hiding the nginx server version.

Ashok Sihmar

Ashok Kumar working in the Search Engine Optimization field since 2015. And worked on many successful projects since then. He shares the real-life experience of best SEO practices with his followers on seoneurons.com. You also can learn Advance level SEO for WordPress, Blogger, or any other blogging platform. Stay tuned.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button