What I normally do is first enable mod_proxy
and mod_proxy_ajp
. Depending on your distribution you a2enmod mod_proxy_ajp
and it enables them both as ajp depends on mod_proxy
.
Then I add something like this:
<IfModule mod_proxy_ajp.c>
<Location /tomcat-context>
ProxyPass ajp://IP-or-FQDN/tomcat-context
ProxyReversePass ajp://IP-or-FQDN/tomcat-context
</Location>
</IfModule>
This part is placed inside my <VirtualHost>
. The rest is basic configuration set by the OS (just like your configuration shows, with ProxyRequests Off
etc.)
UPDATE: What you need to change, or at least verify is your tomcat server.xml. It must have the ajp-container enabled like this:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
You can disable the connector on 8080 if that is all you serve from tomcat and if you do not need the backend. In case you don't have access to this, or ports for ajp are disabled, you can basically achieve the same wirth 8080
. Just replace the ajp:// tag in the provided configuration with http:// and add :8080 after IP-or-FQDN.
UPDATE 2
To serve /
just write
<IfModule mod_proxy_ajp.c>
<Location />
ProxyPass ajp://IP-or-FQDN/tomcat-context
ProxyReversePass ajp://IP-or-FQDN/tomcat-context
</Location>
</IfModule>
Ensure you comment out the DocumentRoot /path/to/old/documentroot/
directive and the <Directory /path/to/old/documentroot/>
in your apache configuration.
Ok, I'll try answering you.
Consider Apache HTTPD and Apache Tomcat two friends (I'll call them in short HTTPD and Tomcat).
Each of them has means of comunicating with other people, let's say by mobile phone and lineland phone or IM.
Tomcat has three phones for recieving calls:
One for recieving international calls in which he speaks the langauage spoken by most people in the (informatic) world, HTTP. This phone has an international agreed subnumber (port) which is 80, but can be any number. It happens that Tomcat being a bit eccentric preferes 8080 by default, so you can speak him HTTP at port 8080 by default.
Another phone for recieving calls from international VIP people, which want to be ultra sure they are speaking with Tomcat and nobody can listen their call, so they speak the previous international language but switching words (encryption, HTTPS). By international agreements this port is 443, but as we said Tomcat is eccentric, he chooses for this port 8443.
The third Tomcat's phone he uses it to recieve calls only from people that speak his own language, AJP (He lives in Java Application Server Country). By International Common Law, it's port 8009.
HTTPD has only two phones for recieving calls
- The first two are the same as for Tomcat but HTTPD is not that eccentric prefering to use the normal agreed numbers, 80 for HTTP and 443 for HTTPS.
The story
Now HTTPD has a shop. Sometimes costumers ask for stuff not present in the shop but when he knows Tomcat has it he calls Tomcat and asks him to bring the things.For speaking with Tomcat HTTPD can use international languages, HTTP and HTTPS, but often Tomcat is more happy to speak his own language, AJP. So HTTPD knows that there are two translators that can help him speak AJP with Tomcat, mod_jk (http://tomcat.apache.org/connectors-doc/) and mod_proxy_ajp (https://httpd.apache.org/docs/2.4/mod/mod_proxy_ajp.html).
Now being more serious, by default, HTTPD listens on ports 80 for HTTP and port 443 for HTTPS.
Tomcat listens on port 8080 for HTTP, port 8443 for https and port 8009 for AJP.
You can configure the ports for HTTPS using Listen directives in it's configuration file, httpd.conf or files included from it. So grep for Listen to check them.
You can configure Tomcat for the ports in server.xml. In Tomcat language those are connectors (as opposed to Listen in HTTPD). And as for your configuration, if you setup Tomcat to use HTTPS he will redirect requests in HTTP to the port configured.
Keep in mind, HTTPD keeps care of his ports, Tomcat of his own ports and a port can be in listen only from a single application at a time. So if you have both HTTPD and Tomcat in the same machine, they fit nicely, as the ports used are different by default:
HTTPD: Ports 80 and 443
Tomcat: Ports 8080 8443 and 8009.
Best Answer
Apache httpd added HTTP/2 proxy support from 2.4.21 but suggest you run latest (2.4.27 at time of writing) as this module is still changing quite a bit at the moment.
Tomcat has just added HTTP/2 support in Tomcat 9: https://readlearncode.com/configure-tomcat-9-for-http2/
So in theory this should all fit together nicely if you're willing to upgrade to those versions (and install OpenSSL 1.0.2 or above required for HTTP/2).
However, in practice it's still all very new, so bugs are possible. To be perfectly honest, the biggest gains from HTTP/2 are with higher-latency connections like client-to-server. Server-to-server connections like Apache to Tomcat using mod_proxy will see fewer gains.
So, given how new these are, you may wish to just use HTTP/2 on your Apache web server (or any other web server which supports HTTP/2), and use mod_proxy to connect to Tomcat via HTTP/1.1 or AJP. This will give you most of the performance gains of HTTP/2 without the hassle and risk of upgrading everything to get full end-to-end HTTP/2.