How can I set use mod_proxy_ajp with Apache and Tomcat?

11,250

You shouldn't need to make any changes to the server.xml except to put Tomcat back to the default ports so Apache can handle port 80. The bulk of the work will be done through the Apache configuration files. I typically leave these outside of the httpd.conf and instead stick them into smaller config snippets under the <ServerRoot>/conf.d/ sub-directory.

Given your example of ourserver.ourcompany.com/app1 & ourserver.ourcompany.com/app2 I would I would assume a configuration something along the following:

<VirtualHost *:80>
    ServerName ourserver.ourcompany.com
    ErrorLog ...
    CustomLog ...

    [other VHost configurations]

    ProxyPass /app1 ajp://tomcat_hostname:8009/app1
    ProxyPassReverse /app1 ajp://tomcat_hostname:8009/app1

    ProxyPass /app2 ajp://tomcat_hostname:8009/app2
    ProxyPassReverse /app2 ajp://tomcat_hostname:8009/app2
</VirtualHost>

If you have multiple Tomcat servers clustered behind then you might want to look at setting up mod_balancer and moving the ajp:// to mod_balancer BalancerMember's and replace with the balancer:// URL that refers to the balancer configuration.

Share:
11,250

Related videos on Youtube

Agvorth
Author by

Agvorth

Updated on September 17, 2022

Comments

  • Agvorth
    Agvorth almost 2 years

    I'd like to run Apache and Tomcat on an RHEL 5 server with Apache handling Ruby on Rails apps (through mod_rails/Passenger) and Tomcat handling Java apps.

    Under Apache, each Rails app will have a URL and vhost. The URLs are already configured in our DNS server to point to the machine.

    Under Tomcat, each Java app has a URL like this: ourserver.ourcompany.com/app1, ourserver.ourcompany.com/app2, etc.

    The server is already up and running with Tomcat 6 running on port 80 and serving several Java apps. I want to add Apache and reconfigure. I'm familiar with how to configure a sole Apache server to host RoR apps using Passenger. I just don't know how to get Apache and Tomcat to work together like that.

    I've found various resources and discussions through Googling (for example, this one) but they tend to be a bit sketchy and incomplete or they don't seem to really match what I'm trying to do. The one I linked to seems to be for if you want to send all requests to Tomcat, not just certain ones and have Apache handle others.

    Could someone suggest an example config for server.xml and httpd.conf, or perhaps point me to some resources that are more detailed?