How to setup Apache as reverse proxy for Tomcat

This is configuration to setup Apache 2.4.41 as reverse proxy for Tomcat 9.0 on Ubuntu 22. 

  1. Install mod-jk   sudo apt install libapache2-mod-jk
  2. Setup workers.properties – Open if exists or create a file workers.properties in /etc/apache2 and paste the following:
    # Define 1 real worker using ajp13
    worker.list=worker1
    # Set properties for worker (ajp13) - use of ip address apparently this solved some problems
    worker.worker1.type=ajp13
    worker.worker1.host=127.0.0.1
    worker.worker1.port=8009
  3. Edit jk.conf to tell Apache how to find Tomcat, I used /etc/apache2/mods-available/httpd-jk.conf (Or /etc/apache2/mods-available/jk.conf, if it exits).In this file, change the JkWorkersFile property to the path where you created workers.properties (OR wherever you have your worker.properties) 
    JkWorkersFile /etc/apache2/workers.properties
  4. Open /etc/apache2/sites-enabled/000-default.conf and
    • Update ServerAdmin to whatever email you like to use [Optional]
    • add the JkMount line in your VirtualHost configuration, inside <VirtualHost *:80> tag
      JkMount /* worker1
  5. Make Tomcat 9.0 Server.xml changes, like so:
    • Comment connectors with 80, 8080 and 443, uncomment/enable “ajp/1.3” Connector with port 8009 [or whatever port you like, but you will need to use that in worker.properties]
    • Add property secretRequired=”false” in ajp connector element, use ip address in element 127.0.0.1 [This applies to newer versions of Tomcat only]
  6. Add Include in apache2.conf
    Include /etc/apache2/mods-available/httpd-jk.conf
  7. Add JkStatus and JkManager entries in worker.properties
    worker.list=jk-status
    worker.jk-status.type=status 
    worker.jk-status.read_only=true 
    worker.list=jk-manager 
    worker.jk-manager.type=status
  8. Restart Tomcat and Apache2.