<\/span><\/h2>\n\n\n\nIf you want to increase your website speed, Gzip compression is considered a high-priority recommendation by site speed test tools.<\/p>\n\n\n\n
Gzip compression used to reduce the size of files request by client’s web browser. This will reduce the amount of time required to transfer a resource from the server to a browser. It utilizes less network bandwidth and improves the page load time for slow connections, while also reducing your file size by up to 70%.<\/p>\n\n\n\n
We also recommended to configure NGINX so that it only compresses large files and avoids smaller files. You can enable the Gzip compression by editing the Nginx virtual host configuration file:<\/p>\n\n\n\n
nano \/etc\/nginx\/sites-enabled\/your-domain.conf<\/pre>\n\n\n\nAdd the following lines within “http {” section:<\/p>\n\n\n\n
gzip on;
gzip_disable \"msie6\";
gzip_vary on;
gzip_proxied any;
gzip_min_length 1024;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text\/plain text\/css application\/json application\/javascript text\/xml application\/xml application\/xml+rss text\/javascript;<\/p><\/pre>\n\n\n\n
Save the file then restart the Nginx service to apply the changes.<\/p>\n\n\n\n
systemctl restart nginx<\/pre>\n\n\n\nNext, you can verify the Gzip compression with the following command:<\/p>\n\n\n\n
curl -I -H 'Accept-Encoding: gzip' http:\/\/your-domain.com\/<\/pre>\n\n\n\nIf Gzip compression is enabled, you should see the “Content-Encoding: gzip” in the following output:<\/p>\n\n\n\n
HTTP\/1.1 200 OK
Server: nginx\/1.4.6 (Ubuntu)
Date: Tue, 01 Sep 2020 07:54:04 GMT
Content-Type: text\/html
Last-Modified: Tue, 04 Mar 2014 11:46:45 GMT
Connection: keep-alive
Content-Encoding: gzip<\/pre>\n\n\n\n<\/span>Enable HTTP\/2 Support<\/span><\/h2>\n\n\n\nBy default, Nginx is configured to use HTTP\/1 protocol. Compared to HTTP\/1, HTTP\/2 has a lot of benefits as it allows a web browser to download files in parallel, and allowing the server to push resources, among others. Currently, HTTP\/2 has gained the popularity due to its performance features. Enabling this can help speed up your Nginx website.<\/p>\n\n\n\n
Features<\/strong><\/p>\n\n\n\n- Binary Nature<\/li>
- Multiplexing<\/li>
- Uses header compression<\/li>
- Uses one connection for parallelism<\/li>
- Implements server push<\/li><\/ul>\n\n\n\n
Before enabling HTTP\/2 on Nginx, it is necessary to enable HTTPS on your server because almost all browsers allow HTTP\/2 only over HTTPS.<\/p>\n\n\n\n
You can enable HTTP\/2 by editing the Nginx virtual host configuration file:<\/p>\n\n\n\n
nano \/etc\/nginx\/sites-enabled\/your-domain.conf<\/pre>\n\n\n\nFind the following line:<\/p>\n\n\n\n
listen 443 ssl;<\/pre>\n\n\n\nAnd, replace it with the following line:<\/p>\n\n\n\n
listen 443 ssl http2;<\/pre>\n\n\n\nSave and close the file then restart the Nginx service to apply the changes.<\/p>\n\n\n\n
systemctl restart nginx<\/pre>\n\n\n\nNext, verify the HTTP\/2 protocol with the following command:\n\n<\/p>\n\n\n\n
curl -I https:\/\/your-domain.com<\/pre>\n\n\n\nRunning that should give you this kind of output:<\/mark>
<\/p>\n\n\n\nHTTP\/2 200
server: nginx
date: Tue, 01 Sep 2020 08:19:13 GMT
content-type: text\/html; charset=UTF-8
vary: Accept-Encoding
x-powered-by: your-domain.com<\/pre>\n\n\n\n<\/span>Configure Worker Processes to Improve Speed<\/span><\/h2>\n\n\n\nA worker process is a single-threaded process. Nginx has a one or more worker processes and each capable of processing a large number of simultaneous connections. By default, the worker process value is set to auto in Nginx default configuration. It is recommended to set 1 worker process per CPU core. Adding more worker processes will almost always improve the speed of your Nginx server.<\/p>\n\n\n\n
You can configure the Worker process by editing your Nginx main configuration file:<\/p>\n\n\n\n
nano \/etc\/nginx\/nginx.conf<\/pre>\n\n\n\nFind the following line:<\/p>\n\n\n\n
worker_processes auto;<\/pre>\n\n\n\nAnd, replace it with the following line as per your CPU cores:<\/p>\n\n\n\n
worker_processes 1;<\/pre>\n\n\n\nSave and close the file then restart the Nginx service to apply the changes.<\/p>\n\n\n\n