Author Topic: Issue with Enabling GZIP module on CWP  (Read 13314 times)

0 Members and 3 Guests are viewing this topic.

Offline
*
Issue with Enabling GZIP module on CWP
« on: May 09, 2017, 06:16:55 AM »
We are using Centos Web Panel.

Our Server information are mentioned below.

Apache version: Apache/2.4.25
PHP version: 5.6.30

We have enabled gzip as per the article

http://forum.centos-webpanel.com/informations/activating-gzip-mod_deflate-and-enabling-caching-on-apache/

After enabling the module, when I do curl request, sometimes gzip is working and sometimes, its not.

=====
curl -I -H  "Accept-Encoding: gzip"   http://domain.tld/main.css
HTTP/1.1 200 OK
Date: Tue, 09 May 2017 05:51:18 GMT
Server: Apache/2.4.25 (Unix) OpenSSL/1.0.1e-fips
Last-Modified: Thu, 04 May 2017 07:08:11 GMT
ETag: "c6cfc-54ead6f892950-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
=====

===
 curl -I -H  "Accept-Encoding: gzip"   http://domain.tld/main.css
HTTP/1.1 200 OK
Date: Tue, 09 May 2017 05:53:47 GMT
Server: Apache/2.4.25 (Unix) OpenSSL/1.0.1e-fips
Last-Modified: Thu, 04 May 2017 07:08:11 GMT
ETag: "c6cfc-54ead6f892950"
Accept-Ranges: bytes
Content-Length: 814332
Cache-Control: public
Content-Type: text/css

===

We are running with "CWP version: 0.9.8.231 ". We have checked the website on "https://checkgzipcompression.com". It also sometimes reports that gzip enabled and sometimes gzip not enabled.

Can someone please help me out to resolve the issue?
« Last Edit: May 09, 2017, 06:33:56 AM by pheonixsolutions »

Offline
*
Re: Issue with Enabling GZIP module on CWP
« Reply #1 on: May 09, 2017, 07:35:08 PM »
Have you tried all solutions posted there?
Yesterday I added my solution:
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: Issue with Enabling GZIP module on CWP
« Reply #2 on: May 10, 2017, 08:26:50 AM »
Hello Karel,

Thanks for your reply.  Now, I have tried the solution and its still the same result.

================
# curl -I -H 'Accept-Encoding: gzip,deflate' https://domain.tld/style.css
HTTP/1.1 200 OK
Date: Wed, 10 May 2017 08:22:20 GMT
Server: Apache/2.4.25 (Unix) OpenSSL/1.0.1e-fips
Last-Modified: Thu, 04 May 2017 07:23:07 GMT
Accept-Ranges: bytes
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Cache-Control: public
Expires: Fri, 09 Jun 2017 08:22:20 GMT
Content-Length: 34313
Content-Type: text/css

# curl -I -H 'Accept-Encoding: gzip,deflate' https://domain.tld/style.css
HTTP/1.1 200 OK
Date: Wed, 10 May 2017 08:22:22 GMT
Server: Apache/2.4.25 (Unix) OpenSSL/1.0.1e-fips
Last-Modified: Thu, 04 May 2017 07:23:07 GMT
ETag: "3f329-54eada4f391c1"
Accept-Ranges: bytes
Content-Length: 258857
Cache-Control: public
Content-Type: text/css
===============

Have you tried all solutions posted there?
Yesterday I added my solution:
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>

Offline
*
Re: Issue with Enabling GZIP module on CWP
« Reply #3 on: May 10, 2017, 06:29:25 PM »
Some other issue must play here.
I noticed your examples are .css files. Most likely the are cached, and when cached no need to download them, therefore no gzip connection needed. <-- Just a guess.

I noticed your output had still ETag: something, where my empty.conf disables Etags.
Did you restart httpd after each configuration modification?
Hobby home server with CentOS 7 + CWP (NAT-ed Mod enabled).

Offline
*
Re: Issue with Enabling GZIP module on CWP
« Reply #4 on: May 14, 2017, 07:20:18 AM »
Hello Karl,

Thanks for the update.

Yes, I have restarted apache.

>>I noticed your examples are .css files. Most likely the are cached, and when cached no need to download them, therefore no gzip connection needed
This may be correct because the we have added expire however we are not sure. The online compression website shows as gzip enabled sometimes and sometimes its not.