How to enable gzip compression on nginx?

Created:

2016-11-16 12:55:04 UTC

Modified:

2017-08-16 16:07:29 UTC

33

Was this article helpful?


Have more questions?

Submit a request

How to enable gzip compression on nginx?

Applicable to:

  • Plesk 12.5 for Linux
  • Plesk Onyx for Linux
  • Plesk 11.x for Linux
  • Plesk 12.0 for Linux

Question

The ngx_http_gzip_module module is a filter that compresses responses using the gzip method. It often helps to reduce the size of transmitted data by half or even more.

How to enable it globally?

Answer

  1. Connect to the server using SSH.
  2. Create a file using the command ' vi /etc/nginx/conf.d/gzip.conf ' and put the following content in it:

    gzip         on;
    gzip_disable "MSIE [1-6]\\.(?!.*SV1)";
    gzip_proxied any;
    gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp image/svg+xml;
    gzip_vary on;

    Note: This is an example. It is possible to add other file types in gzip_types, e.g. application/javascript , application/js , etc.

  3. Test the configuration and fix errors (if any):

    # nginx -t
  4. Reload nginx configuration:

    # service nginx reload

Other gzip_types available for compression can be obtained from /etc/nginx/mime.types .

If it is needed to enable this module for a single domain, add the aforementioned content in the Domains > example.com > Apache & nginx Settings > Additional nginx directives.

nginx.png

More about gzip compression module can be found in nginx manual .

Have more questions? Submit a request

1 Comments

Please sign in to leave a comment.