Howtos / Articles

Enable GZIP compression in Nginx

All commonly used web browsers nowadays support GZIP compression, so enabling this on your web server is a great way to decrease how much data you are sending out, and in turn, speed up your site. While it may not make a huge difference on a small site, you may notice a big difference on a busy site.

With Nginx, enabling GZIP compression is a simple process that involves adding a few commands to your main ‘nginx.conf’ configuration file.

Open the Nginx configration file in your favorite text editor.

Locate the ‘http’ section.

The start of this section can be identified by the line starting with “http {” and the end of this section is identified by the next line that contains a single “}” character.

Anywhere within this ‘http’ section, add the following lines, if they don’t already exist. If they already exist, modify them to suit.

    gzip  on;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_types      text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

Change the ‘gzip_types’ line to contain any other mime types that you would like to send using gzip compression.

Save the file, and exit the editor.

Restart the Nginx server.

Your Nginx web server should now be serving out the files matching the mime types listed in the config using gzip compression.



Share this howto article!
  • Facebook
  • Twitter
  • Reddit
  • email

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>