WF AQ

Knowledge base

How to enable gzip compression for nginx on Plesk server

  1. Connect to the server using SSH.
  2. Create a text file using the following command:

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

  3. Open the file in any text editor, for example, using vi:

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

  4. Insert the following content in it:

    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/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 section, e.g. application/javascript, application/js, etc. The full list of available types can be viewed on a server directly in /etc/nginx/mime.types file

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

    # nginx -t

  6. Reload nginx configuration:

    # service nginx reload

  7. To check if gzip compression enabled use the command below. When gzip enabled you will see in the output ‘Content-Encoding: gzip’:

    # curl -s -H “Accept-Encoding: gzip” -I http://domain.tld | grep Content-Encoding
    Content-Encoding: gzip