tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier>
Subject Re: setup default webapp in tomcat 6 and apache
Date Thu, 15 Jan 2009 23:22:11 GMT
johnrock wrote:
[.. plenty]

Just one little trick, which you may have missed in the Apache/Tomcat docs :
the JkMount/JkUnMount directives may sometimes be a bit clumsy to 
handle. You can replace them by something like this in Apache :

<Location /xyz>  (or <LocationMatch>)
   SetHandler jakarta-servlet

That does about the same as a
JkMount /xyz worker1
and it's easier to figure out at which "level" it plays, relative to 
Apache configuration directives (like authentication etc..).

The above appears somewhere on a page of the Apache/Tomcat connector 
docs, at the very bottom of a long page.
It gives you all the flexibility of the Apache Location and 
LocationMatch (regexp), to decide what you want to send to Tomcat and 
what not.  The JkMount syntax is less flexible.

You can also use mod_rewrite.
And you can use "SetEnvIf xxxx no-jk" to prevent a URL normally 
redirected to Tomcat, to be.

Some examples follow. There is a bit of overlap between some of the 
stuff below, but they are there to show what is possible.
All of that is pretty-well documented in Apache and Tomcat on-line docs, 
but it helps to know where to look for it.
I hope it helps you chew on your problem.

	RewriteEngine On

	# to see what rewrites do :
	RewriteLog /var/log/apache2/rewrite.log
	RewriteLogLevel 2

	# If not a webapp call, but it starts with "/xyz/" anyway,
	# remove the "/xyz/" prefix.
	# This allows us to serve static objects referenced relatively
	# in Tomcat-controlled pages, like
	# <img src="images/stuff.jpg">
	RewriteCond %{REQUEST_URI} !/servlet\.[^\.]+$
	RewriteRule ^/xyz/(.*)$ /$1 [PT]

	# For testing, set a var which allows us later to condition
	# other stuff (like logging)
	#SetEnvIf REQUEST_URI "/servlet\.[^\.]+$" is-jk

	# Have Apache process most static content, Tomcat process
	# the rest.  The important bit is the "no-jk" var, which
	# will cause mod_jk to DECLINE.
	SetEnvIf REQUEST_URI "\.(css|gif|jpg|js|html?)$" no-jk

	# The following assumes all Tomcat links follow some
	# pattern, like "/servlet.myservlet?..query_params.."
	<LocationMatch "/servlet\.[^.]+$">
		# Replaces JkMount/JkUnMount directives
		SetHandler jakarta-servlet
		# For debugging with FireFox's LiveHttpHeaders :
		Header always set Tomcat-did-this: "yes"
	# The following denies access through Apache to Tomcat
	# sensitive stuff (assuming some private Tomcat stuff ends
	# in such extensions)
	<FilesMatch "\.(xxx|zzz)$">
		Order allow,deny
		Deny from all
	# don't let them ask for your web.xml e.g.
   	<LocationMatch "/WEB-INF/.*$">
		Order allow,deny
		Deny from all

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message