Home Nginx Enable Nginx Gzip Compression – Ubuntu 18.04 & 16.04

Enable Nginx Gzip Compression – Ubuntu 18.04 & 16.04

0
Gzip Compression

Enable Nginx Gzip Compression – Ubuntu 18.04 & 16.04 – Nginx, stylized as NGINX or nginx or NginX, is a web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. The software was created by Igor Sysoev and publicly released in 2004. Nginx is free and open-source software, released under the terms of the 2-clause BSD license.

What are the 10 advantages of Nginx?

  1. Installations and configurations are simple and easy

  2. Fastest and the best for serving static files

  3. Dynamic content transformed into static content

  4. When compared to Apache, 4 times more concurrent connections are handled.

  5. Compatibility with commonly-used web apps

  6. Load Balancing Support

  7. Nginx makes websites faster thereby enabling them to get higher ranking by Google

  8. No risk in switching over to Nginx

  9. Support from Nginx service professionals

  10. The unique opportunity to try something new

Why is it important?

The main reason it is important is because it reduces the time it takes for a website to transfer the page files and style sheets which ultimately reduces the load time of your website.

What is Gzip compression?

When a user hits your website a call is made to your server to deliver the requested files.

The bigger these files are the longer it’s going to take for them to get to your browser and appear on the screen.

Gzip/Brotli compresses your webpages and style sheets before sending them over to the browser. This drastically reduces transfer time since the files are much smaller.

In terms of cost versus benefit, compression should be near the top of your page speed optimizations if you don’t have it setup already.

How does it work?

Gzip/Brotli is actually a fairly simple idea that is extremely powerful when put to good use. Gzip/Brotli locates similar strings within a text file and replaces those strings temporarily to make the overall file size smaller.

The reason gzip/Brotli works so well in a web environment is because CSS files and HTML files use a lot of repeated text and have loads of whitespace. Since gzip/Brotli compresses common strings, this can reduce the size of pages and style sheets by up to 70%!

Gzip/Brotli has to be enabled on your webserver which is relatively straight forward.

When a browser visits a webserver it checks to see if the server has gzip/Brotli enabled and requests the webpage. If it’s enabled it receives the gzip/Brotli file which is significantly smaller and if it isn’t, it still receives the page, only the uncompressed version which is much larger.

Enable Nginx Gzip Compression on Nginx?

Configuring Nginx’s gzip Settings

To change the Nginx gzip configuration, open the main Nginx configuration file in nano or your favorite text editor.

$  sudo nano /etc/nginx/nginx.conf

Find the gzip settings section, which looks like this:

##
        # Gzip Settings
        ##

        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 text/xml application/xml application/xml+rss text/javascript;

You can see that by default, gzip compression is enabled by the gzip on directive, but several additional settings are commented out with # comment sign. We’ll make several changes to this section

Once you done please reload Nginx to take effect changes

$  sudo systemctl reload nginx

Related Articles

Enable Apache Gzip Compression – Ubuntu 18.04 & 16.04

How to test Gzip Compression

Sample Gzip Test Result

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exit mobile version