Sometimes it is better to have the web server serve the static pages (html, gif, jpeg etc.)
even if these files are part of a context served by Tomcat. For example, consider the html and gif files in the examples context, there is no need to serve them from the Tomcat process. The web server can do it on its own.
Making the web server serve static files that are part of the Tomcat contexts requires the following:
-
Configuring the web server to know about the Tomcat contexts
-
Make sure that the WEB-INF and META-INF directories are protected from access.
-
Configuring the web server to assign the NSAPI redirector only specific requests that requires JSP/Servlet handling.
Adding the contents of a Tomcat context to the web server requires the addition of a new virtual directory
that covers the Tomcat context.
For example, adding a /example virtual directory that
covers the c:\tomcat\webapps\examples directory.
To add a new virtual directory add the following line to your obj.conf:
NameTrans fn=pfx2dir from=/examples dir="c:/tomcat/webapps/examples"
WEB-INF protection requires some explanation; Each servlet application (context) has a special directory named WEB-INF,
this directory contains sensitive configurations data and Java classes and must be kept hidden from web users.
A second directory that should be protected is META-INF.
Those directories can be protected by adding the following line to the PathCheck section in the default configuration object:
PathCheck fn="deny-existence" path="*/WEB-INF/*"
PathCheck fn="deny-existence" path="*/META-INF/*"
These lines instruct the web server to reject any request with a URL that contains the path /WEB-INF/
or /META-INF/.
Configuring the web server to assign the NSAPI redirector only specific requests is somewhat harder,
you will need to specify the exact URL-Path pattern(s) that you want Tomcat to handle
(usually only JSP files and servlets).
This requires a change to NameTrans portion of obj.conf.
For the examples context it requires to replace the following line:
NameTrans fn="assign-name" from="/examples/*" name="jknsapi"
with the following two lines:
NameTrans fn="assign-name" from="/examples/jsp/*.jsp" name="jknsapi"
NameTrans fn="assign-name" from="/examples/servlet/*" name="jknsapi"
As you can see the second configuration is more explicit, it actually instructs
the web server to assign the redirector with only requests to resources under
/examples/servlet/ and resources under /examples/ whose name ends with .jsp.
You can be even more explicit and provide lines such as:
NameTrans fn="assign-name" from="/examples/servlets/chat" name="jknsapi"
Instructs the web server to assign the redirector requests whose URL path equals /example/servlets/chat