Skip to end of metadataGo to start of metadata
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.
Summary This module requires the service of modproxy. It provides the features used for proxying HTTP and HTTPS requests. Modproxyhttp supports HTTP/0.9, HTTP/1.0 and HTTP/1.1. It does not provide any caching abilities. Modproxyhtml is an output filter to rewrite HTML links in a proxy situation, to ensure that links work for users outside the proxy. It serves the same purpose as Apache's ProxyPassReverse directive does for HTTP headers, and is an essential component of a reverse proxy. For example, if a company has an application server at appserver.example.com that is only visible from within the company. Apache httpd 1.3 and later versions support an optional module (modproxy) that configures the web server to act as a proxy server.This can be used to forward requests for a particular web application to a Tomcat instance, without having to configure a web connector such as modjk.
Prerequisites
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. |
Httpd Mod_proxy_html
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.
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:
Httpd Mod_proxy_wstunnel
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.
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.
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.
Apache2 Proxy
Description: | HTTP/1.1 proxy/gateway server |
---|---|
Status: | Extension |
Module Identifier: | proxy_module |
Source File: | mod_proxy.c |
Summary
Warning
Do not enable proxying with ProxyRequests
until you have secured your server. Open proxy servers are dangerous both to your network and to the Internet at large.
This module implements a proxy/gateway for Apache. It implements proxying capability for AJP13
(Apache JServe Protocol version 1.3), FTP
, CONNECT
(for SSL), HTTP/0.9
, HTTP/1.0
, and HTTP/1.1
. The module can be configured to connect to other proxy modules for these and other protocols.
Apache's proxy features are divided into several modules in addition to mod_proxy
: mod_proxy_http
, mod_proxy_ftp
, mod_proxy_ajp
, mod_proxy_balancer
, and mod_proxy_connect
. Thus, if you want to use one or more of the particular proxy functions, load mod_proxy
and the appropriate module(s) into the server (either statically at compile-time or dynamically via the LoadModule
directive).
In addition, extended features are provided by other modules. Caching is provided by mod_cache
and related modules. The ability to contact remote servers using the SSL/TLS protocol is provided by the SSLProxy*
directives of mod_ssl
. These additional modules will need to be loaded and configured to take advantage of these features.