Enable Nginx Gzip Compression

Gzip is a software application, has .gz file format used on Unix and Unix-like systems to compress HTTP content including images, medias, javascript, css files before it’s served to a client or browser. Here we will enable Nginx Gzip Compression.

Open Nginx configuration file

sudo nano /etc/nginx/nginx.conf

Edit Nginx Configuration file

sudo vi /etc/nginx/nginx.conf

Enable Nginx Gzip compression

Uncomment the below code in nginx.conf, if this code is not available in file then paste this code in nginx.conf.

#gzip on;

         #gzip_vary on;
         #gzip_proxied any;
         #gzip_comp_level 6;
         #gzip_buffers 16 8k;
         #gzip_http_version 1.1;
         #gzip_types text/plain text/css application/json application/javascript$

Now, press CTRL + X and then press Y button.

Now, Gzip is enabled and we need to restart the nginx. Use below commands to restart the nginx.

sudo service nginx reload

or 

sudo systemctl restart nginx

For more code examples click here. Nginx documentation here