Chapter 17 Configuring Proxy Support

Web applications can request for the server name and port number of the request with the use of Tomcat standard configurations. A running Tomcat with the Coyote HTTP/1.1 Connector generates the server name specified in the request and the port number onto which the Connector listens. The following lists the servlet API calls of interest:

  • ServletRequest.getServerName(): This returns the host name of the server to which the request was sent.
  • ServletRequest.getServerPort(): This returns the host name of the server to which the request was sent.
  • ServletRequest.getLocalName(): This returns the host name of the Internet Protocol interface on which the request was received.
  • ServletRequest.getLocalPort(): This returns the Internet Protocol port number of the interface on which the request was received.

Configurations

  • Apache 1.3 Proxy Support – The Apache 1.3 supports mod_proxy, an optional module, that configures the web server to act as a proxy server. You can use this module to forward requests for a particular web application to a Tomcat 6 instance without configuration of a web connector. Perform the following steps:

1. Configure Apache and include the mod_proxy module.

2. Load mod_proxy module at Apache startup time. Use the following directives in the httpd.conf file:

 LoadModule proxy_module {path-to-modules}/mod_proxy.so
AddModule mod_proxy.c

3. If you wish to forward a web application to Tomcat 5, include two directives in the httpd.conf file.

Example:
ProxyPass /myapp http://localhost:8081/myapp
ProxyPassReverse /myapp http://localhost:8081/myapp

This example informs Apache to forward URLs of the form http://localhost/myapp/* to the Tomcat 5 connector listening on the port 8081.

4. Configure the copy of Tomcat 5 and include a special element with appropriate proxy settings.

Example:

<Connector port="8081"....
    proxyName="www.mycompany.com" 
    proxyPort="80"/>

5. If you delete the proxyName attribute from the <Connector> element, the value returned by request.getServerName() will be the host name on which Tomcat is running.

6. If you have a <Connector> listening on port 8080, the requests to either port share the same set of virtual hosts and web applications.

7. You can use the IP filtering features of the operating system to restrict connections to port 8081.

8. You can set up a series of web applications that are only available through proxying:

  • Configure another <Service> that contains only a <Connector> for the proxy port.
  • Configure appropriate Engine, Host, and Context elements for virtual hosts and web applications which can be accessed through proxying.
  • You may protect port 8081 with IP filters.

9. Web server records requests in its access log when requests are proxied by Apache.


  • Currently 3.02/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
  Flag Inappropriate Content 0 comments