disable gzip compression in apache

How to Disable GZIP Compression in Apache

Enabling GZIP compression on your web server allows you to improve website speed and performance by compressing response data before sending it to the client browser. But sometimes it may not work as you expect or cause issues instead. In such cases you may need to disable GZIP compression on your website. In this article, we will look at how to disable GZIP compression in Apache web server.


How to Disable GZIP Compression in Apache

Here is how to disable GZIP compression in Apache. You may completely disable GZIP, or only for specific file types. We will look at both these cases.


1. Disable GZIP compression completely

Ubuntu/Debian

Open terminal and run the following command to completely disable gzip compression on your server across all websites

$ sudo a2dismod deflate

Restart Apache Server

$ sudo service apache2 restart

Redhat/CentOS/Fedora

Open Apache configuration file

$ sudo vi /etc/apache2/httpd.conf

Comment out the following line 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 certain file types

Sometimes GZIP may be malfunctioning for only certain file types such as .jpg, .png, etc. In such cases, open .htaccess file on your website.

$ sudo vi /var/www/html/.htaccess

Add the following lines to disable GZIP compression for JPG & PNG files.

<IfModule mod_headers.c>
    <FilesMatch "\.(jpg|png)$">
        RewriteRule ^(.*)$ $1 [NS,E=no-gzip:1,E=dont-vary:1]
    </FilesMatch>
</IfModule>

The above code disabled gzip for .jpg and .png files using RewriteRule directive. Alternatively, you may use SetEnv directive to disable gzip compression for these files. It sets no-gzip flag for these URLs to 1 thereby disabling it.

# for files that end with ".py" 
<FilesMatch \.(jpg|png)$>
     SetEnv no-gzip 1 
</FilesMatch>

Save and close the file.

Restart apache server.

$ sudo service apache2 restart

Also, if you want to disable gzip for URLs in a particular folder, then also you can use SetEnv directive.

# for URL paths that begin with "/foo/bar/" 
SetEnvIf Request_URI ^/foo/bar/ no-gzip=1 

In this article, we have looked at how to disable gzip compression for several use cases – all websites on a server, specific file types & URLs, specific folders.

GZIP compression is a very useful feature used by most websites in the world to improve website performance and reduce bandwidth consumption. However, if it is not working for you, we suggest you find out for which URLs it is causing issues, and disable GZIP only for those URLs using use case No.2 above, instead of disabling GZIP compression for your entire website. Once you have fixed the issue with those URLs, you can always re-enable GZIP for them.

Also read:

How to Install Specific Version of NPM package
How to Disable TLS 1.0 in Apache
How to Force User to Change Password in Linux
Shell Script to Automate SSH Login
How to Pause Shell Script

Leave a Reply

Your email address will not be published. Required fields are marked *