TheRedAaron wrote:
I'be bought 2 domains and want both to host web apps on one Linode server. I can set up different web apps in Tomcat no problem but where do I tell what to send each web request to the right app on Tomcat?
Here's how I use Apache and Tomcat together on Ubuntu:
1) In /etc/apache2/conf.d I have two .conf files, one for http traffic and one for https. In the http one for example, I have <VirtualHost ipaddress:port> sections for each site I host in Tomcat or on whatever backend server I wanted like Ruby (that'll never happen).
2) In each of those <VirtualHost sections I don't use rule rewriting I'd just get myself into trouble so I do something very simple ... oh and I don't use that mod_jk connector either. I just do this ... for each site in its respective <VirtualHost section near the bottom of the section I put in two symbols (you need mod_proxy installed in Apache):
Code:
# main site, I've had this set though I think Tomcat
# works fine with it off, the default, depends on the needs
# of the backend server
ProxyPreserveHost On
# main site, trailing slash is important in general
ProxyPass / http://127.0.0.1:8080/MyMainSite/
ProxyPassReverse / http://127.0.0.1:8080/MyMainSite/
# main site, one more thing I did but might not be
# needed for the main site, can't remember why now
ProxyPass /MyMainSite http://127.0.0.1:8080/MyMainSite/
ProxyPassReverse /MyMainSite http://127.0.0.1:8080/MyMainSite/
# remaining sites just these two are needed
# site FooTrain, trailing slash is important in general
ProxyPass / http://127.0.0.1:8080/FooTrain/
ProxyPassReverse / http://127.0.0.1:8080/FooTrain/
# site GlobalFoo, trailing slash is important in general
ProxyPass / http://127.0.0.1:8080/GlobalFoo/
ProxyPassReverse / http://127.0.0.1:8080/GlobalFoo/
...etc.
One nice thing about this configuration is that one SSL certificate protects all the content for my main site whether the content comes from Tomcat or Apache or any other backend server that I choose to configure with a ProxyPass ProxyPassReverse combination.
Good luck!
PS I run Tomcat in its own account using a script:
Code:
# checktomcatrunning.sh
#!/bin/sh
wget --spider 127.0.0.1:8080
STATUS=$?
if [ "$STATUS" = "0" ]; then
echo running
else
echo stopped, restarting Tomcat
# run the standard tomcat startup.sh
/home/tomcataccountname/bin/runtomcat.sh
fi
And I run that checktomcatrunning.sh script from the account's cron:
Code:
* * * * * /home/tomcataccountname/bin/checktomcatrunning.sh >/dev/null 2>&1
Hope this helps.