Applicable to:
- Plesk for Linux
Question
How to enable gzip compression in Apache?
Answer
Note: Since Plesk Obsidian 18.0.33 it is possible to use BROTLI compression which is considered to be better compression than GZIP.
Note: In case Smart static files processing is enabled in Domains > example.com > Apache & nginx Settings, disable it, or use the following article instead: How to enable gzip compression in nginx on a Plesk server
-
Make sure that 'deflate' and 'filter' modules ('filter' might be absent on CentOS 6) are enabled in Tools & Settings > Apache Web Server.
-
Go to Domains > example.com > File Manager and open the
.htaccess
file. -
Add the following content to the bottom of the file:
CONFIG_TEXT: <IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
Note: In case Smart static files processing is enabled on domain in Domains > example.com > Apache & nginx Settings, disable it, or use the following article instead: How to enable gzip compression in nginx on a Plesk server
-
Connect to the server via SSH
Note: if direct SSH access to the server is not possible, contact server administrator for further assistance.
-
Make sure that module
mod_deflate
is enabled in apache:# httpd -M | grep deflate
deflate_module (shared) -
Create a file
deflate.conf
in/etc/httpd/conf.d:
# vi /etc/httpd/conf.d/deflate.conf
-
Add the following into the file:
CONFIG_TEXT: <IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule> -
Note in case of Centos OS, if the server has Apache 2.4 (httpd-2.4), the following module should be enabled:
# grep -ir "mod_filter.so" /etc/httpd/conf.modules.d/00-base.conf
LoadModule filter_module modules/mod_filter.soIn case of Debian and Ubuntu, check that the filter_module is enabled:
# apachectl -M | grep filter
filter_module (shared) -
Restart Apache:
# service httpd restart
Note: On Debian and Ubuntu the service is named apache2 instead of httpd, the list of all modules is called using apache2ctl utility and the path for deflate.conf
file is /etc/apache2/mods-available/
instead of /etc/httpd/conf.d/
Comments
0 comments
Please sign in to leave a comment.