Setting up virtual hosts and connectors with Railo and Apache

Yesterday’s twitter brought me a couple of questions regarding Railo to Apache connections. Marrying the two is actually straightforward although it will require settings changes in both applications. How does it work? Let’s walk the process step by step:

Step 1. Railo without Apache
Railo is running on Tomcat. You do not need Apache to access Railo applications in the first place. That means that you can configure your Tomcat to run on port 80 and forget about Apache (or Nginx or any other front-end webserver) altogether. To achieve this open the Tomcat configuration file /Railo/tomcat/conf/server.xml and change the HTTP/1.1 connector port to 80:

 <Connector port="80" protocol="HTTP/1.1" 
     redirectPort="8443" />

NB! Make sure that port 80 is free and available or your Tomcat won’t restart.
Restart Railo from the Server Administrator page and voila, you are running it on port 80 and your Railo application is now accessible at http://localhost

Step 2. Adding virtual hosts to Railo/Tomcat
You are still serving Railo using Tomcat as a webserver but you would like to add a couple of virtual hosts to your setup. Make sure that your domain names are pointing to (or whatever server IP address you are using) and open the same /Railo/tomcat/conf/server.xml Tomcat configuration file.
Add your virtual hosts to the Engine section like this:

<Host name="railoapplication1.local"  appBase="webapps"
    unpackWARs="true" autoDeploy="true"
    xmlValidation="false" xmlNamespaceAware="false">
    <Context path="" docBase="/Railo/tomcat/webapps/railoapplication1"/>
<Host name="railoapplication2.local"  appBase="webapps"
    unpackWARs="true" autoDeploy="true"
    xmlValidation="false" xmlNamespaceAware="false">
    <Context path="" docBase="/Railo/tomcat/webapps/railoapplication2"/>


  • Host name is a URL you are using such as railoapplication1.local
  • DocBase should point to the root of your Railo application

Restart Railo from the Server Administrator page. You have just added two virtual hosts running Railo on Tomcat.

Step 3. Adding Apache connectors
There are good reasons for adding a front-end webserver such as Apache or Nginx to your application such as separation of static from dynamic traffic, load balancing, front-end caching or using Apache rewrites. To do this:

  • Reconfigure your Tomcat to run on port 8080 using Step 1. You can use any other free port you like. Restart Railo.
  • Configure your Railo virtual hosts as described in Step 2. Verify them running at port 8080.
  • Open your Apache virtual hosts configuration file. Mine is located at /etc/apache2/extra/httpd-vhosts.conf. We are going to serve Railo applications using Apache as a reverse proxy. Add your virtual hosts to Apache and configure it to connect to Railo instead of serving from files from the filesystem. Your virtual host definition will probably look like this:
    <VirtualHost *:80>
        DocumentRoot "/Railo/tomcat/webapps/railoapplication1"
        ServerName railoapplication1.local
        ServerAlias www.railoapplication1.local
        ProxyRequests Off
        <Proxy *>
          Order deny,allow
          Allow from all
        ProxyPass / http://railoapplication1.local:8080/
        ProxyPassReverse / http://railoapplication1.local:8080/
  • Restart Apache:

    sudo apachectl restart

    That’s it. No magic. Have a good day!