how to disable mod_deflate in apache

How to Disable mod_deflate in Apache

mod_deflate is an Apache server module that performs data compression while sending response to client browsers, thereby increasing website speed and improving performance. Sometimes you may need to disable mod_deflate in Apache server. In this article, we will look at how to disable mod_deflate in Apache.


How to Disable mod_deflate in Apache

Here are the steps to disable mod_deflate in Apache server.


1. Disable mod_deflate

We will look at different use cases to disable mod_deflate below.


Disable mod_deflate for all URLs and files

Here are the steps to disable mod_deflate completely for all file types in Apache server.

Ubuntu/Debian

Open terminal and run the following command to disable mod_deflate in Ubuntu/Debian systems.

$ sudo a2dismod deflate

Redhat/Fedora/CentOS

Open Apache configuration file in a text editor.

$ sudo vi /etc/httpd/conf/httpd.conf

Look for the following line

LoadModule deflate_module modules/mod_deflate.so

Comment it by adding # at its beginning

#LoadModule deflate_module modules/mod_deflate.so

Save and close the file.


Disable mod_deflate for certain files

If you want to disable mod_deflate only for specific file types such as .py or .php files and not all files, then open .htaccess file.

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

Add the following block in it to disable mod_deflate for .py files.

<FilesMatch \.py$>
    SetEnv no-gzip 1
</FilesMatch>

Save and close the file. In the above case, we flag our target files as no-gzip so that they are excluded from compression.


Disable mod_deflate for certain URLs

If you want to disable mod_deflate for specific URLs such as those beginning with /test/product, then open .htaccess file.

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

Add the following SetEnv statement to .htaccess file. Replace /test/product with URL of your requirement.

SetEnvIf Request_URI ^/test/product/ no-gzip=1

Save and close the file. In the above case, we flag our target URLs as no-gzip so that they are excluded from compression.


2. Restart Apache server

Restart Apache server to apply changes.

$ sudo service apache2 restart

That’s it. You can use an online header checker to check if gzip is disabled for your website. In this article, we have looked how to disable mod_deflate for all URLs, some specific files, and specific URLs. You can use the appropriate steps depending on your requirement.

Also read:

How to Stop/Prevent SSH Brute Force Attacks
How to Disable SSH Root Login in Linux
How to Open, Extract RAR Files in Linux
How to Stop Linux Package Update in Ubuntu
How to Generate PGP Key in Ubuntu

Leave a Reply

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