Skip to end of metadataGo to start of metadata
- Apache Httpd Tomcat Load Balancing
- Apache Httpd Tomcat
- Apache Httpd Tomcat Mod_proxy
- Apache Tomcat 8.5
- Apache Mod_jk Tomcat
In this How-To guide, we will show you how to fix broken links when using a reverse proxy between your Apache webserver and your Tomcat server.

I have configured my server to use httpd as proxy and Tomcat for deploying and running application. I use Apache httpd as proxy to redirect all request to port 80 and to the directory of tomcat where my web application files are located: /usr/share/tomcat/webapps/website. The Apache HTTP Server ('httpd') was launched in 1995 and it has been the most popular web server on the Internet since April 1996. It has celebrated its 25th birthday as a project in February 2020. The Apache HTTP Server is a project of The Apache Software Foundation.
Tomcat and apache httpd training 1. Tomcat and Apache httpd Objectives version 1.1 2. Objectives install Java, Tomcat, Apache httpd configure Tomcat build and monitor database connection pools monitor Tomcat secure Java EE web application understand Apache https configuration files set up and configure modjk build Tomcat clusters to ensure high availability antislashn.org Tomcat and Apache. Introduction Using Apache httpd as a proxy to an Apache Tomcat application container is a common setup. It comes with many use cases, the most trivial is serving static content from httpd, while providing services implementing heavy business logic from an application written in Java that resides in the Tomcat container. In simple terms, this means that the HTTP Connector is exposed to clients, while the AJP is used internally between the webserver (e.g., Apache HTTPD) and the Apache Tomcat server (illustrated in Figure 1). AJP is implemented as a module in the Apache HTTP Server, represented as modjk or modproxyajp.
Prerequisites
Apache Httpd Tomcat Load Balancing
For this you are going to need the following
mod_proxy_html | http://apache.webthing.com/mod_proxy_html/mod_proxy_html.c | mod_proxy_html to fix hyperlinks. |
libxml2 | http://xmlsoft.org/ | Needed by mod_proxy_html. Should be included in most, if not all, Linux distributions. |

mod_proxy_html directives can be used in following contexts - server config, virtual host, and in <Location>. The examples below will be in the server config context as well as pertain to Apache that has been compiled with the source package from http://httpd.apache.org.
To fix the links in Tomcat pages, we are using mod_proxy_html. This is necessary for proxied pages that use links that are resolved with a URI path or with an absolute URL.
Links in proxied pages that are set up in the manner above will not work. The first will resolve to http://localhost/somefile which is incorrect compared to the way the reverse proxy to Tomcat was set up. To correctly resolve somefile, the link would need to use http://localhost/webapps/somefile. The second link example will yield a 'No such server' error for the browser. This also affects images and other resources linked this way on the proxied page. Thus the need to fix these link types with mod_proxy_html.
If you can guarantee that all your links will be of the form:
then using mod_proxy_html will not be necessary. Although, for Tomcat, the management page will contain bad URIs.
Apache Httpd Tomcat
Since mod_proxy_html is not included in the Apache package, you need to either download and compile it or get your distro's package, if available. To compile it, we use the apxs binary that comes with the Apache package.

/path/to/ is the path to where apxs and your libxml2 header files are at. You only need to specify the -I/path/to/include/libxml2 if the libxml2 header files are not in a standard location. Using the apxs command will compile and build the module. It will also put in the correct LoadModule in httpd.conf:
Note: If you get errors starting up Apache regarding mod_proxy_html and libxml2, you can add the LoadFile directive below before the LoadModule directives.
Apache Httpd Tomcat Mod_proxy
Make sure /path/to is your real system path to the libxml2.so library.
With the module compiled, built and loaded, we can now use mod_proxy_html to fix links. To use the mod_proxy_html directives, you need to make sure that if <IfModule mime_module> is being used, then you must put the directives in that <IfModule> block. If this block isn't being used, then you can put the directives anywhere in your server configuration file. The Tomcat management page will be used in the following example. Spotify app for mac.
Apache Tomcat 8.5

Apache Mod_jk Tomcat
As you can see from the example above, mod_proxy_html can use regular expressions to do its matching which is denoted by the 'R' at the end of the ProxyHTMLURLMap lines. You can check the management page by accessing http://localhost/webapps and clicking the Tomcat Manager link (http://localhost/webapps/manager/html). Click on the links on this page and you will see that all the links resolve correctly. If we didn't fix the links, then all the links on Tomcat's management page will yield 404 errors from the browser.
For more complete information on mod_proxy_html, visit Nick Kew's mod_proxy_html page.
