The Apache Tomcat 5.5 Servlet/JSP Container

0


Hyperlinks

Person Information

Reference

Apache Tomcat Improvement

Proxy Assist HOW-TO

Introduction

Utilizing normal configurations of Tomcat, net purposes can ask for the server identify and port quantity to which the request was directed for processing. When Tomcat is working standalone with the Coyote HTTP/1.1 Connector, it is going to typically report the server identify specified within the request, and the port quantity on which the Connector is listening. The servlet API calls of curiosity, for this function, are:

  • ServletRequest.getServerName(): Returns the host identify of the server to which the request was despatched.
  • ServletRequest.getServerPort(): Returns the host identify of the server to which the request was despatched.
  • ServletRequest.getLocalName(): Returns the host identify of the Web Protocol (IP) interface on which the request was obtained.
  • ServletRequest.getLocalPort(): Returns the Web Protocol (IP) port variety of the interface on which the request was obtained.

If you find yourself working behind a proxy server (or an internet server that’s configured to behave like a proxy server), you’ll typically choose to handle the values returned by these calls. Particularly, you’ll typically need the port quantity to replicate that specified within the authentic request, not the one on which the Connector itself is listening. You should utilize the proxyName and proxyPort attributes on the factor to configure these values.

Proxy help can take many types. The next sections describe proxy configurations for a number of frequent instances.

Apache 1.3 Proxy Assist

Apache 1.3 helps an non-compulsory module (mod_proxy) that configures the online server to behave as a proxy server. This can be utilized to ahead requests for a selected net utility to a Tomcat 5 occasion, with out having to configure an internet connector corresponding to mod_jk. To perform this, you want to carry out the next duties:

  1. Configure your copy of Apache in order that it consists of the mod_proxy module. If you’re constructing from supply, the simplest approach to do that is to incorporate the –enable-module=proxy directive on the ./configure command line.
  2. If not already added for you, just remember to are loading the mod_proxy module at Apache startup time, by utilizing the following directives in your httpd.conf file:
  3. Embody two directives in your httpd.conf file for every net utility that you just want to ahead to Tomcat 5. For instance, to ahead an utility at context path /myapp: which tells Apache to ahead URLs of the shape http://localhost/myapp/* to the Tomcat 5 connector listening on port 8081.
  4. Configure your copy of Tomcat 5 to incorporate a particular factor, with applicable proxy settings, for instance: which is able to trigger servlets inside this net utility to suppose that all proxied requests had been directed to www.mycompany.com on port 80.
  5. It’s authorized to omit the proxyName attribute from the factor. For those who achieve this, the worth returned by request.getServerName() will by the host identify on which Tomcat is working. Within the instance above, it could be localhost.
  6. For those who even have a listening on port 8080 (nested throughout the identical Service factor), the requests to both port will share the identical set of digital hosts and net purposes.
  7. You would possibly want to use the IP filtering options of your working system to limit connections to port 8081 (on this instance) to be allowed solely from the server that’s working Apache.
  8. Alternatively, you possibly can arrange a collection of net purposes which might be solely obtainable by way of proxying, as follows:
    • Configure one other that accommodates solely a for the proxy port.
    • Configure applicable Engine, Host, and Context components for the digital hosts and net purposes accessible by way of proxying.
    • Optionally, shield port 8081 with IP filters as described earlier.
  9. When requests are proxied by Apache, the online server might be recording these requests in its entry log. Subsequently, you’ll typically need to disable any entry logging carried out by Tomcat itself.

When requests are proxied on this method, all requests for the configured net purposes might be processed by Tomcat (together with requests for static content material). You’ll be able to enhance efficiency by utilizing the mod_jk net connector as a substitute of mod_proxy. mod_jk could be configured in order that the online server serves static content material that isn’t processed by filters or safety constraints outlined throughout the net utility’s deployment descriptor (/WEB-INF/net.xml).

Apache 2.0 Proxy Assist

The identical directions maintain true as for 1.3. (Besides in Apache 2.0, chances are you’ll omit AddModule mod_proxy.c)

Supply

You might also like