GZIP compression allows a web server to compress its response data before sending it to web browsers, thereby improving website speed and reducing network bandwidth. But sometimes you may experience issues while using GZIP on your web server. In such cases, you will need to disable GZIP compression in Apache. In this article, we will learn how to disable GZIP compression in Apache server.
How to Disable GZIP Compression in Apache
You can either completely disable GZIP compression in Apache, or choose to disable GZIP compression for specific file types, as per your requirement. We will look at both these methods.
1. Completely Disable GZIP Compression
Depending on your Linux system, use the appropriate methods to disable GZIP.
Ubuntu/Debian
Open terminal and run the following command to disable GZIP compression.
$ sudo a2dismod deflate
Restart Apache server to apply changes.
$ sudo service apache2 restart
Redhat/CentOS/Fedora
Open Apache configuration file.
$ vi /etc/apache2/httpd.conf
Look for the following line and comment it by adding # at its beginning.
LoadModule deflate_module modules/mod_deflate.so
Restart Apache Server.
$ sudo /etc/init.d/httpd restart
2. Disable GZIP Compression for File Types
If you are facing compression issues only for specific file types, then you can disable GZIP compression only for those file types, until you fix the problem. For this case, open .htaccess file in text editor.
$ vi /var/www/html/.htaccess
Add the following line to disable GZIP compression for JPG and PNG files, RewriteRule directive.
<IfModule mod_headers.c>
<FilesMatch "\.(jpg|png)$">
RewriteRule ^(.*)$ $1 [NS,E=no-gzip:1,E=dont-vary:1]
</FilesMatch>
</IfModule>
You can also use SetEnv directive to set no-gzip file to 1, for desired file types.
# for files that end with ".jpg" and ".png"
<FilesMatch \.(jpg|png)$>
SetEnv no-gzip 1
</FilesMatch>
You can also disable GZIP compression for specific URL or folder. Here is an example to disable GZIP compression for specific folder.
# for URL paths that begin with "/foo/bar/"
SetEnvIf Request_URI ^/foo/bar/ no-gzip=1
Save and close the file. Restart Apache server.
$ sudo service apache2 restart
In this article, we have learnt several ways to disable GZIP compression – for entire website, specific file types, URLs and folders.
Depending on your requirement, you can disable GZIP compression until you fix the issue, before re-enabling it. It is always recommended to keep GZIP compression enabled on your website to improve its performance and speed.
Also read:
How to Disable TLS 1.0 in Apache
Shell Script to Automate SSH Login
How to Force User to Change Password in Linux
How to Pause Shell Script
How to Send HTML Mail Using Python
Related posts:
Sreeram Sreenivasan loves coding & writing tech articles. He has helped many Fortune 500 companies in the areas of BI & software development. He has more than 10 years of experience in web development, Python, Linux, SQL and database programming.