Apache and Tomcat: Proxy, Caching and Compression configuration

947 views
Skip to first unread message

P.G.Taboada

unread,
Jan 27, 2011, 7:20:51 AM1/27/11
to Google Web Toolkit
Hi there,

it took me a while to get all pieces together so I wanted to share my
configuration. I have an apache as a proxy, tomcat serving the app and
lots of clients. So I wanted to setup compression and expiration
headers properly.

http://bit.ly/GwtApacheConfig

Anyone with a better config?

brgds,

Papick

Ed

unread,
Jan 27, 2011, 8:31:15 AM1/27/11
to Google Web Toolkit
Thanks.
A few things:
- ProxyPassReverse don't work with ajp...
See: http://www.humboldt.co.uk/2009/02/the-mystery-of-proxypassreverse.html
You can simple test it by performing a redirect on tomcat

- Almost all browsers nowedays support gzip, so why not gzip them by
default..?.. instead of gzipping them on every http request... not
needed...
You can tell GWT to output all your files as gzip. Then use apache
httpd multiview to send the correct file.
Then let apache httpd inflate the file if you encounter a browser that
doesn't support gzip..(rare these days).

- Use Yslow plugin for FF to fine tune your settings.

- Don't forget to set the correct caching for the css, images, third
party js files, etc...

- Put your gwt files directly under apache httpd instead of tomcat
(noserver mode). Performs much better. Only use tomcat for rpc and
other backend calls.
Then you don't need the proxymatch settings and just use Files
settings...performs a bit better...

- See: http://groups.google.com/group/google-web-toolkit/browse_thread/thread/7c81c942706241a3#

I got this all working very nice and you notice the performance gain
big time as I also have the nightly build without all these optimized
http settings...

Here you got a http snippet that I use, hope it helps you:
----
# Add inflate (uncompress) filter that will be used when the browser
doesn't support
# gzip
# Ref: http://httpd.apache.org/docs/2.2/mod/mod_filter.html
FilterDeclare gzinflate CONTENT_SET
FilterProvider gzinflate inflate req=Accept-Encoding !$gzip


# set up Multiviews:
# Ref:
# http://www.w3.org/International/questions/qa-apache-lang-neg
# http://httpd.apache.org/docs/current/content-negotiation.html
# http://everything2.com/title/How+to+get+Apache+to+send+compressed+versions+of+static+HTML+files
# Note: make sure to not set the "AddType application/x-gzip .gz .tgz"
as then all the gzp files will
# be returned with the wrong content-type (as gzip instead as the
zipped content: js/css, etc...)

Options +MultiViews
AddEncoding x-gzip .gz
RemoveType application/x-gzip .gz .tgz

# Enabled the inflate filter
FilterChain gzinflate



# GWT Optimization.
# ref:
# http://www.infoq.com/articles/gwt-high-ajax
# http://code.google.com/webtoolkit/doc/latest/DevGuideCompilingAndDebugging.html
# http://www.samaxes.com/2008/04/htaccess-gzip-and-cache-your-site-for-faster-loading-and-bandwidth-saving/
# http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/
# http://code.google.com/p/doctype/wiki/ArticleHttpCaching
#
## GWT caching
#
<Files *.nocache.*>
ExpiresActive on
ExpiresDefault "now"
Header set Cache-Control "public, max-age=0, must-revalidate"
</Files>

<Files *.cache.*>
ExpiresActive on
ExpiresDefault "now plus 1 year"
</Files>

# Note: this only matches the file name and not the preceding
directory
<FilesMatch "\.(gif|jpe?g|png|ico|css|xml)$">
ExpiresActive on
ExpiresDefault "now plus 3 day"
</FilesMatch>

<Files ext.js>
ExpiresActive on
ExpiresDefault "now plus 3 day"
</Files>

# Tell apache to use the compressed files if possible
#SetOutputFilter DEFLATE
#
# Deflate by type
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# ref: http://developer.yahoo.com/performance/rules.html#etags
FileETag none

P.G.Taboada

unread,
Jan 27, 2011, 1:57:48 PM1/27/11
to Google Web Toolkit
Thanks a lot for your comments. I am trying not to take static
resources out of tomcat as it would make deployment slightly more
complicated, but I have it in mind as soon as I run into performance
issues.

I am struggling a little bit with the split points: although http
headers are set to expire in far future, the browser keeps reloading
the split points (the .js files).

I will update my posting to include your comments asap.

brgds,

Papick

On Jan 27, 2:31 pm, Ed <post2edb...@gmail.com> wrote:
> Thanks.
> A few things:
> - ProxyPassReverse don't work with ajp...
> See:http://www.humboldt.co.uk/2009/02/the-mystery-of-proxypassreverse.html
> You can simple test it by performing a redirect on tomcat
>
> - Almost all browsers nowedays support gzip, so why not gzip them by
> default..?.. instead of gzipping them on every http request... not
> needed...
> You can tell GWT to output all your files as gzip. Then use apache
> httpd multiview to send the correct file.
> Then let apache httpd inflate the file if you encounter a browser that
> doesn't support gzip..(rare these days).
>
> - Use Yslow plugin for FF to fine tune your settings.
>
> - Don't forget to set the correct caching for the css, images, third
> party js files, etc...
>
> - Put your gwt files directly under apache httpd instead of tomcat
> (noserver mode). Performs much better. Only use tomcat for rpc and
> other backend calls.
> Then you don't need the proxymatch settings and just use Files
> settings...performs a bit better...
>
> - See:http://groups.google.com/group/google-web-toolkit/browse_thread/threa...
>
> I got this all working very nice and you notice the performance gain
> big time as I also have the nightly build without all these optimized
> http settings...
>
> Here you got a http snippet that I use, hope it helps you:
> ----
> # Add inflate (uncompress) filter that will be used when the browser
> doesn't support
> # gzip
> # Ref:http://httpd.apache.org/docs/2.2/mod/mod_filter.html
>  FilterDeclare gzinflate CONTENT_SET
>  FilterProvider gzinflate inflate req=Accept-Encoding !$gzip
>
> # set up Multiviews:
> # Ref:
> #http://www.w3.org/International/questions/qa-apache-lang-neg
> #http://httpd.apache.org/docs/current/content-negotiation.html
> #http://everything2.com/title/How+to+get+Apache+to+send+compressed+ver...
> # Note: make sure to not set the "AddType application/x-gzip .gz .tgz"
> as then all the gzp files will
> # be returned with the wrong content-type (as gzip instead as the
> zipped content: js/css, etc...)
>
>  Options +MultiViews
>  AddEncoding x-gzip .gz
>  RemoveType application/x-gzip .gz .tgz
>
>  # Enabled the inflate filter
>  FilterChain gzinflate
>
> # GWT Optimization.
> # ref:
> #http://www.infoq.com/articles/gwt-high-ajax
> #http://code.google.com/webtoolkit/doc/latest/DevGuideCompilingAndDebu...
> #http://www.samaxes.com/2008/04/htaccess-gzip-and-cache-your-site-for-...
> #http://betterexplained.com/articles/how-to-optimize-your-site-with-gz...
> #http://code.google.com/p/doctype/wiki/ArticleHttpCaching
Reply all
Reply to author
Forward
0 new messages