Setting up virtual hosts
At the moment I presume both domains will end up sending http requests to whatever server is listening to the 80/8080 ports and just return the default page for the server.
I've got as far as virtual hosts but I'm really looking for a bit of a leg up to save some time. Do I need to route the requests through Apache or do people manage the virtual hosting in Tomcat?
Thanks in advance.
2 Replies
@TheRedAaron:
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
2) In each of those
# 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:
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:
- * * * * /home/tomcataccountname/bin/checktomcatrunning.sh >/dev/null 2>&1
````
Hope this helps.