Enabling gzip compression for a domain in Plesk
- In Plesk, go to Domains > example.com > Apache & nginx Settings.
- Add the following directives to the Additional nginx directives field:
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
.
- Click Apply to save the changes.
Disabling gzip compression for a domain in Plesk
- In Plesk, go to Domains > example.com > Apache & nginx Settings.
Note: To disable gzip compression for a domain/subdomain that does not exist in Plesk (e.g. hostname), create it first.
- Add the following directive to the Additional nginx directives field:
gzip off;
- Click Apply to save the changes.
For all domains via nginx global configuration
Note: All the commands in sections below should be executed as ‘root
‘ user or using ‘sudo
‘
Enabling gzip compression server-wide
- Connect to a server via SSH.
- Create the
gzip.conf
file inside nginx conf.d directory:
# touch /etc/nginx/conf.d/gzip.conf
- Open the file in any text editor.
# vi /etc/nginx/conf.d/gzip.conf
- 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/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
.
- Test nginx configuration:
# nginx -t
- Reload
nginx
configuration to apply the changes:
# service nginx reload
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
- Connect to a server via SSH.
- Search for the line in “gzip on” via all nginx config files:
# grep -Ri "gzip on" /etc/nginx/
- To disable gzip compression, open the corresponding file in a text editor and change
gzip on
togzip off
. - Save the changes and close the file.
- Reload nginx configuration to apply the changes:
# service nginx reload