Question

How to enable compression for a particular webspace on a WebHosting Linux server?

Answer

The Apache module mod_deflate is supported since Odin Automation 7.3. Also, it is necessary that on the web server was running under CloudLinux 6.0 or higher.

First of all, make sure the mod_deflate module is enabled:

[root@linweb httpd]# grep -i deflate /etc/httpd/conf/httpd.conf
LOADMODULE deflate_module modules/mod_deflate.so

[root@linweb httpd]# apachectl -M | grep -i deflate
[Thu Jun 07 11:02:17 2018] [notice] POA VHosts: module has registered its hooks.
Syntax OK
 deflate_module (shared)

To enable compression on a particular website, follow the below steps:

  1. Go to the website directory:

    # cd /var/www/vhosts/3/100007/webspace/httpdocs/example.com
    
  2. Add the below line to the .htaccess file:

    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
    
  3. Check that the response header Content-Encoding: gzip is present and the content is compressed:

    [root@linweb ~]# curl -i -H 'Accept-Encoding: gzip,deflate' http://example.com/index.html
    HTTP/1.1 200 OK
    Date: Thu, 07 Jun 2018 05:18:06 GMT
    Server: Apache
    X-SERVER: 11
    Last-Modified: Fri, 18 May 2018 10:47:46 GMT
    ETag: "20-56c78aeb0b588"
    Accept-Ranges: bytes
    Vary: Accept-Encoding
    Content-Encoding: gzip
    Content-Length: 46
    Content-Type: text/html
    
    ▒▒(▒ͱ▒
    ▒▒,V▒▒ʼt▒▒▒.▒!n▒▒ 
    

See also:

Internal content