Author Topic: Activating gzip,mod_deflate and enabling caching on Apache  (Read 31278 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Activating gzip,mod_deflate and enabling caching on Apache
« on: December 10, 2015, 04:42:09 PM »
If you want to optimize your website and for increasing seo score:


Login Centos Web Panel,Goto Apache Settings/ Apache vHosts Template and Insert the following Lines   :

1) Activating gzip and  compressing css, images and js files with mod_deflate on Apache

Find this lines  :

<Directory "%homedir%/%username%/public_html">
AllowOverride All

*Add after: (Ensure, this lines should be between  "<Directory> </Directory>"

<IfModule mod_mime.c>
   AddType application/x-javascript .js
   AddType text/css .css
   </IfModule>
 
<IfModule mod_deflate.c>
   AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/plain text/xml application/javascript
   <IfModule mod_setenvif.c>
      BrowserMatch ^Mozilla/4 gzip-only-text/html
      BrowserMatch ^Mozilla/4.0[678] no-gzip
      BrowserMatch MSIE !no-gzip !gzip-only-text/html
   </IfModule>
</IfModule>

2) Make Browsers Cache Static Files With mod_expires On Apache
Insert this line :

<IfModule mod_expires.c>
    ExpiresActive on
 
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
</IfModule>

Preview:





Now we should click "Rebuild Virtual Hosts", then click "Rebuild All Virtual Hosts for activating changes on the all websites:


All ok.

You can check status with this website :

http://checkgzipcompression.com/



If you want to reverse changes , you should go this folder and restore last files  on ftp : /usr/local/cwp/.conf/backups/file_editor_backups/

Offline
*
Re: Activating gzip,mod_deflate and enabling caching on Apache
« Reply #1 on: November 27, 2016, 04:01:12 PM »
thanks for the great article, but I am getting error:

Code: [Select]
Starting httpd: httpd: Syntax error on line 419 of /usr/local/apache/conf/httpd.conf: Syntax error on line 29 of /usr/local/apache/conf.d/vhosts.conf:  directive requires additional arguments
[FAILED]

please help.

Offline
*****
Re: Activating gzip,mod_deflate and enabling caching on Apache
« Reply #2 on: November 28, 2016, 05:37:32 AM »
thanks for the great article, but I am getting error:

Code: [Select]
Starting httpd: httpd: Syntax error on line 419 of /usr/local/apache/conf/httpd.conf: Syntax error on line 29 of /usr/local/apache/conf.d/vhosts.conf:  directive requires additional arguments
[FAILED]

please help.
add this lines to .htaccess :
Code: [Select]
<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>

Offline
*
Re: Activating gzip,mod_deflate and enabling caching on Apache
« Reply #3 on: December 14, 2016, 07:16:29 AM »
thank you very much for this tutorial

it help me and it's working better now  :)

Offline
*
Re: Activating gzip,mod_deflate and enabling caching on Apache
« Reply #4 on: December 25, 2016, 11:40:17 AM »
Thanks for the instructrions - after having followed them exactly and after having no errors in output, I checked them on
http://checkgzipcompression.com/ - none of the domains or subdomains have gzip enabled....

Only problem I can see ( and that has got nothing to do with the 'main' domains) is that the rebuild shows that some of the subdomains, although working fine, seems to be missing their IP for some reason)

Well - here is an update:

I ran the rebuild v hosts several times and managed to get all domains gzip enabled.

I discovered however, taht many of my subdomains - although working fine - are NOT in the vhost list....? Any idea why?



What can be wrong?


Ok - here´s latest update on this:

After paying a support ticket to CWPfolks, they discovered that the missing gzip and other problems was caused by a bug in cwp, and that bug was corrected in cwp 0.9.8.131 - I checked and that solution solved the bug.

BUT - not in the SSL enabled domains (infact that is all of them...;-) - here gzip implementing after the above description does not work, not even when adding the code manually....

Any ideas?

« Last Edit: December 29, 2016, 01:34:29 PM by muscator »

Offline
*
Re: Activating gzip,mod_deflate and enabling caching on Apache
« Reply #5 on: March 29, 2017, 04:18:38 PM »
Best solution in my case. Centos7:

- Verify if module is loaded in your httpd.conf file:
/index.php?module=file_editor&file=/usr/local/apache/conf/httpd.conf

- Place the following in it:
Quote
# mod_deflate configuration
<IfModule mod_deflate.c>
 
# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
 
# Level of compression (Highest 9 - Lowest 1)
DeflateCompressionLevel 9
 
# Netscape 4.x has some problems.
BrowserMatch ^Mozilla/4 gzip-only-text/html
 
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
 
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
 
</IfModule>


Offline
*
Re: Activating gzip,mod_deflate and enabling caching on Apache
« Reply #6 on: May 08, 2017, 07:38:43 PM »
This thread got me thinking. The above solutions do work but I think \usr\local\apache\conf.d\empty.conf is a better place to add custom settings which will survive updates and rebuilds.

Directly edit as root: \usr\local\apache\conf.d\empty.conf
or go to your cwp and navigate to Apache Settings --> Apache Include conf --> select empty.conf
(admin/index.php?module=file_editor&file=/usr/local/apache/conf.d/empty.conf)

I added compressing (mod_deflate), caching and some security.

Code: [Select]
### file to edit \usr\local\apache\conf.d\empty.conf
### Caching, compress and some security added thanks to https://www.gebruikers.eu
# Load mod_deflate.so only if it is not previously enabled, check httpd.conf for this.
# In my case it wasn't enabled. I prefer this empty.conf to load mod_deflate so my config survives updates and rebuilds.
LoadModule deflate_module modules/mod_deflate.so

<Location />
# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# Don't compress images and other uncompressible content
SetEnvIfNoCase Request_URI \
 \.(?:gif|jpe?g|png|rar|zip|exe|flv|swf|mov|wma|mp3|mp4|avi|mp?g)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>

# BEGIN Compress text files
<ifModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
    AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml
    AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml
    AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript application/json
    AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf
    AddOutputFilterByType DEFLATE font/truetype font/opentype
</ifModule>
# END Compress text files and caching

# BEGIN Expire headers https://samaxes.com/2011/05/improving-web-performance-with-apache-and-htaccess/
<ifModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 5 seconds"
    ExpiresByType text/html "access plus 1 second"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType text/javascript "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 week"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
    ExpiresByType application/xhtml+xml "access plus 1 second"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 month"
</ifModule>
# END Expire headers

# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
    <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
        Header set Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(css)$">
        Header set Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(js)$">
        Header set Cache-Control "private"
    </filesMatch>
    <filesMatch "\.(x?html?|php)$">
        Header set Cache-Control "private, must-revalidate"
    </filesMatch>
    </ifModule>
# END Cache-Control Headers

# BEGIN Turn ETags Off
    FileETag None
# END Turn ETags Off

# Protection against malicious code in files imposing as images
#ForceType application/octet-stream
<FilesMatch "(?i).jpe?g$">
    ForceType image/jpeg
</FilesMatch>
<FilesMatch "(?i).gif$">
    ForceType image/gif
</FilesMatch>
<FilesMatch "(?i).png$">
    ForceType image/png
</FilesMatch>
Hobby home server with CentOS 7 + CWP (NAT-ed Mod enabled).

Offline
*
Re: Activating gzip,mod_deflate and enabling caching on Apache
« Reply #7 on: March 17, 2020, 09:52:23 AM »
Hello,

I have a problem with cWP pro,
Why cant do gzip from file manger on client panel?
Only zip and tar is working,  gzip not?!

Offline
*****
Re: Activating gzip,mod_deflate and enabling caching on Apache
« Reply #8 on: March 18, 2020, 06:15:23 AM »
it will be on new file manager