Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Say I have a registered URL mywebsite.com pointing to my server with a public IP address.

I want to run both tomcat and apache to serve pages (i.e., some static pages on apache and some dynamic pages on tomcat, like jsp etc...).

For the sake of simplicity, let's assume that apache is listening on 80 and tomcat on 8080.

I heard about mod_proxy. Is it possible to have requests to mywebsite.com go to apache and mywebsite/loggedin go to tomcat? If yes, how should this be configured and where? Thanks.

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

I would recommend using mod_jk--it tends to be more specific than mod_proxy, and easier to debug. You can forward contexts. I.e., if I have webapp1 and webapp2 running on Tomcat, and I have an images directory on Apache, this would work:

<VirtualHost *:80>
    ...
    JKMount /webapp1/* ajp13
    JKMount /webapp2/* ajp13
    Alias /images "/some/local/dir"
</VirtualHost>

This is also much easier to configure, and most distributions already have packages in their native package managers. Hope this helps!

share|improve this answer
add comment

mod_proxy works well with tomcat. There are 2 ways to proxy to tomcat via mod_proxy.

  1. http - So tomcat runs as an http server to and apache talks to tomcat via HTTP
  2. mod_proxy_ajp - This uses the ajp protocol (also used by mod_jk). In this case apache talks to tomcat via a binary protocol which has some better performance.

mod_proxy_ajp is a package which comes with apache as compared to mod_jk which needs to be downloaded and compiled. But mod_jk usually gets new features first and has more options. If your setup is NOT complex ... mod_proxy_ajp is the way to go. In which case in Tomcat, you need to configure tomcat to have a AJP connector. And you will not need an http connector in server.xml. For apache the directive may be as easy as this:

  ProxyPass /loggedin  ajp://127.0.0.2:8009/loggedin 

Proxy docs with ajp examples are here: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

share|improve this answer
    
Thanks, I am currently doing a lot of reading following the answers so far. I surely need a simple solution right now, but I know I'll need something more sophisticated in the future. Climbing the learning curve. –  JVerstry Sep 20 '11 at 11:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.