Articles in this section

How to enable/disable gzip compression in nginx on a Plesk server

DoNotDelete:docref kb: how-to Plesk for Linux ABT: Group A FR:PPM-358 kb: improved

Applicable to:

  • Plesk for Linux

Question

How to enable/disable gzip compression in nginx on a Plesk server?

Answer

Note: Since Plesk Obsidian 18.0.33 it is possible to use BROTLI compression which is considered to be better compression than GZIP.

For a domain in Plesk

 

Enabling gzip compression for a domain in Plesk

 

  1. Log in to Plesk.

  2. Go to Domains > example.com > Hosting & DNS > Apache & nginx Settings.

  3. Add the following directives to the Additional nginx directives field:

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

    Note: This is an example. If needed, add other file types in the gzip_types section, e.g. application/javascript, application/js, etc. The full list of available types can be found on a server in the file /etc/nginx/mime.types.

  4. Apply the changes.

 

Disabling gzip compression for a domain in Plesk

 

  1. Log in to Plesk.

  2. Go to Domains > example.com > Hosting & DNS > Apache & nginx Settings.

    Note: To disable gzip compression for a domain/subdomain that does not exist in Plesk (e.g. hostname), create it first.

  3. Add the following directive to the Additional nginx directives field:

    CONFIG_TEXT: gzip off;

  4. Click Apply to save the changes.

 

 

For all domains via nginx global configuration

 

Enabling gzip compression server-wide

 

  1. Connect to a Plesk server via SSH.

  2. Create the gzip.conf file inside nginx conf.d directory:

    # touch /etc/nginx/conf.d/gzip.conf

  3. Open the file in any text editor. In this example, we are using the vi editor:

    # vi /etc/nginx/conf.d/gzip.conf

  4. Insert the following content in it:

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

    Note: This is an example. If needed, add other file types in the gzip_types section, e.g. application/javascript, application/js, etc. The full list of available types can be found on a server in the file /etc/nginx/mime.types.

  5. Save the changes and close the file.

  6. Test nginx configuration:

    # nginx -t

  7. Reload nginx configuration to apply the changes:

    # service nginx reload

  8. Now gzip compression is enabled for all domains on the server.

    To verify that gzip compression is enabled, use the command below. When gzip is enabled you will see 'Content-Encoding: gzip' in the output:

    Note: If the website has a www redirection, change the website name to www.example.com.

    • If the website is using HTTP connection:

      # curl -s -H "Accept-Encoding: gzip" -I http://example.com | grep -i Content-Encoding
      Content-Encoding: gzip

    • If the website is using HTTPS connection:

      # curl -s -H "Accept-Encoding: gzip" -I https://example.com --insecure | grep -i Content-Encoding
      Content-Encoding: gzip

 

Disabling gzip compression server-wide

 

  1. Connect to a server via SSH.

  2. Search for the line in "gzip on" via all nginx config files:

    # grep -Ri "gzip on" /etc/nginx/

  3. To disable gzip compression, open the corresponding file in a text editor and change gzip on to gzip off.

  4. Save the changes and close the file.

  5. Restart nginx to apply the changes:

    # service nginx restart

 

Additional Information

To learn more about gzip compression module and gzip types, visit the following nginx documentation page:

To enable gzip compression in Apache, visit this KB article.

Was this article helpful?

Comments

1 comment
Date Votes
  • Hello :) I try to host my WebGl project on my server but there is always an error: «Unable to parse Build/museum_video.framework.js.gz! This can happen if build compression was enabled but web server hosting the content was misconfigured to not serve the file with HTTP Response Header "Content-Encoding: gzip" present. Check browser Console and Devtools Network tab to debug». I tired to solve the problem with your first solution «Enabling gzip compression for a domain in Plesk» but that didn’t work. Do you know why? I still have the same error.

    0

Please sign in to leave a comment.