homepage Welcome to WebmasterWorld Guest from 54.198.139.141
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
having trouble making mod gzip work
mcglynn




msg:4082502
 8:28 pm on Feb 17, 2010 (gmt 0)

My LAMP-based website uses zlib in php.ini to compress PHP-generated content. I'm hoping to compress external stylesheets and javascript files via mod_gzip.

I successfully rebuilt apache 1.3.41 with mod_gzip; when I run `httpd -l` I can see mod_gzip listed at the end:

[root@nsc bin]# ./httpd -l
Compiled-in modules:
http_core.c
mod_env.c
mod_log_config.c
mod_mime.c
mod_negotiation.c
mod_status.c
mod_include.c
mod_dir.c
mod_cgi.c
mod_asis.c
mod_actions.c
mod_userdir.c
mod_alias.c
mod_rewrite.c
mod_access.c
mod_auth.c
mod_expires.c
mod_headers.c
mod_so.c
mod_setenvif.c
mod_php5.c
mod_gzip.c

Further, the mod_gzip status page (via the mod_gzip_command_version directive) shows that the module is active:
> mod_gzip is available...
> mod_gzip_version = 1.3.26.1a
> mod_gzip_on = Yes

However, the log I've configured is empty -- Apache creates the logfile but never writes anything to it. And all my tests indicate that CSS and JS files are not getting compressed.

Full config from httpd.conf follows.

I've been banging my head against this for a couple hours. Hopefully someone here will see an obvious mistake. The lines that are commented out were initially enabled, but didn't make this fly either.

To be clear, the point of this is to have mod_gzip skip all the PHP content (and images and audio), but to compress static text files such as .js and .css.

<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_command_version '/(redacted)'
# mod_gzip_can_negotiate Yes
# mod_gzip_static_suffix .gz
# AddEncoding gzip .gz
mod_gzip_temp_dir /var/tmp/mod_gzip
mod_gzip_keep_workfiles No
# mod_gzip_minimum_file_size 500
mod_gzip_maximum_file_size 500000
mod_gzip_maximum_inmem_size 60000
mod_gzip_handle_methods GET POST
mod_gzip_item_exclude file \.html$
mod_gzip_item_exclude file \.php$
mod_gzip_item_exclude file \.pdf$
# mod_gzip_item_exclude mime "application/x-httpd-php"
mod_gzip_item_include file \.css$
mod_gzip_item_include file \.js$
mod_gzip_item_exclude mime ^image/
mod_gzip_item_exclude mime ^audio/
# mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
LogFormat "%h %l %u %t \"%V %r\" %<s %b mod_gzip: %{mod_gzip_result}n In:%{mod_gzip_input_size}n -< Out:%{mod_gzip_output_size}n = %{mod_gzip_compression_ratio}n pct." common_gzip
CustomLog /var/log/httpd/gzip_log common_gzip
mod_gzip_add_header_count Yes
</IfModule>

The above <IfModule> block exists in httpd.conf outside of all the VirtualHost configuration. Do I need to specifically enable mod_gzip within each <VirtualHost> block?

Or would I be better off writing a PHP script that outputs my CSS and JS files, thereby getting compression via zlib and bypassing the need for mod_gzip entirely? I don't like this idea much, but I could do it if that's the best answer.

 

mcglynn




msg:4112542
 7:07 pm on Apr 8, 2010 (gmt 0)

I finally made this work... problem #1 was that the directory in the mod_gzip_temp_dir directive didn't exist. It needs to exist, and be writeable by the apache process owner (nobody).

problem #2 is that the mod_gzip_item_include directives were not working. I replaced the two 'file' selectors with 'mime', e.g.:
mod_gzip_item_include mime ^text/css$
mod_gzip_item_include mime ^application/x-javascript$

jdMorgan




msg:4113846
 1:15 pm on Apr 11, 2010 (gmt 0)

Thanks for posting the solution!

gzip can be a real pain when it doesn't work...

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved