I'm going to assume you've followed the instructions in Part III and have an interim Railo+Tomcat installation already running.
Preparing Tomcat
If Tomcat is running, shut it down (by quitting the org.apache.catalina.startup.Bootstrap application).
First, we want move the Tomcat folder to a more permanent home. Using the Finder, I dragged apache-tomcat-6.0.18 to my /Developer folder but you can put it in your home directory or wherever else you want. Then I renamed it to tomcat so that the directory path is easier to type.
Second, we want to make Railo the 'root' web application so that it no longer needs the /railo prefix on its URLs. In the Finder, I renamed the ROOT folder, under webapps, welcome (you could - and probably should - remove it altogether on production). Then I renamed railo to ROOT.
Then we'll start Tomcat. I used the following shell command:
You could just as easily double-click the Tomcat start script in the bin folder if you followed by tip about renaming startup.sh in the last post.
At this point, we can browse to http://localhost:8080/ and see the Railo test page. I had to force my browser to refresh since it had cached the previous Tomcat welcome page.
If you renamed the old ROOT folder to welcome, as I did, you can still reach it on http://localhost:8080/welcome/.
Enabling Tomcat Users (optional)
If you want to look at the Tomcat Manager console, you need to do one more piece of configuration on Tomcat: adding a Tomcat user. In the Finder, navigate to the conf folder under Tomcat and open tomcat-users.xml with your favorite text editor (I use TextMate because it supports SVN, CFML and a number of other languages but you can easily use the built-in TextEdit application). In the <tomcat-users> section, add a user definition like this:
Restart Tomcat to pick up the change (I thought it might pick up the change automatically but it didn't seem to notice when I saved the file).
Now you can browse to http://localhost:8080/manager/html and you'll be challenged for the username and password you defined above. When you've logged in, you'll see a list of the web applications that are active on Tomcat, along with the number of active sessions and basic controls to stop / start / reload / undeploy the applications. Warning: undeploying an application removes the entire directory structure from webapps! As you'll see, in addition to the Railo web application (now at /), there are web applications for documentation (/docs), examples (/examples) and a couple of 'manager' applications. In production, you would want to remove anything you don't need. Since you can 'manage' Tomcat by editing XML files, you could remove everything except the ROOT (Railo) application.
Two main issues remain at this point:
- The web root is webapps/ROOT/ under the Tomcat install
- We are using port 8080 and not routing through Apache on port 80
Changing the Tomcat web root
By default, Tomcat assumes the web root for each application is a folder under webapps. Also by default, the URL for each web application begins with a 'context root' that is the name of that directory (with the empty context - / - for the ROOT folder). This behavior is controlled by Tomcat's conf/server.xml file. Open it up in your favorite text editor and go to the bottom of the file. You'll see a <Host..> section that defines the behavior for the default virtual host. You can add <Context..> tags inside this section to override the default 'context root' behavior for web applications.
For my setup, I want the web root to be /Users/scorfield/Sites for the empty context so that I can browse a local copy of my corfield.org site. I added:
As you might imagine from reading the comments around the <Host..> tag, you can have multiple hosts defined, each with a different set of applications, each having their own 'context root' and their own web root. Read the Tomcat 6 documentation for more details of what other configurations are possible.
Configuring Apache with Tomcat
In most blog posts, this is always the hardest part to follow. Almost everyone shows how to configure mod_jk which, whilst fairly standard, is a lot of work. For example, see Marko Tomic's post on the Lynch Consulting blog which walks you through building mod_jk from source in order to get Apache up and running.
That's far too much work for my taste and there is a much simpler solution, in my opinion. What a lot of people forget is that Tomcat is a very robust, high performance web server in its own right. With JRun (under ColdFusion), you usually want have Apache handle static content and JRun handle the requests for CFML pages and that's why you would use the JRun connector (which is what ColdFusion installs by default when you tell it to connect to a web server).
You could simply tell Tomcat to use port 80 and leave Apache out of the picture altogether. Just change the port= attribute from 8080 to 80 on the <Connector..> tag for the Catalina service in Tomcat's conf/server.xml file. However, most systems run an existing web server on port 80 and you probably don't want to interfere with that - and instead just connect it to Tomcat.
The easiest way to connect Apache to Tomcat is to proxy requests. This way you have control over which URLs are passed to Tomcat and can easily leverage all the other useful Apache modules. Here's an example of an Apache virtual host for railo.corfield.org (an entry in my /etc/hosts file that points to 127.0.0.1 for testing my site locally):
ServerName railo.corfield.org
DocumentRoot /Users/scorfield/Sites
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
At this point you have Apache+Tomcat+Railo configured and you should be able to set up as many local virtual hosts as you want, each with its own web root and a local configuration of Railo.
In future posts, we'll look at additional ways to configure Apache, Tomcat and Railo. I'll also take a stab at configuring things with IIS at some point.
@Barney, CGI.SERVER_NAME gives me railo.corfield.org with mod_proxy configured as described but, yes, AJP provides more options. The docs say "This is used for cases where you wish to invisibly integrate Tomcat 6 into an existing (or new) Apache installation, and you want Apache to handle the static content contained in the web application, and/or utilize Apache's SSL processing."
For me, this was as simple as replacing http://localhost:8080/ with ajp://localhost:8009/ in the ProxyPass and ProxyPassReverse directives (the Connector for port 8009 is already defined by default in Tomcat).
BTW using: "ProxyPreserveHost on" in the <Vhost/> block sends the host header name through the proxy to tomcat/other webserver rather then the hostname of the apache machine.
I've tried it in tomcats server.xml --> error was that after Virtualhost there must be > or />
Then tried it in httpd.conf --> error was that ProxyRequests is an invalid command
I've also to mention, that one has also to enable these modules for apache e.g. in this case all of the proxy-Modules.
Also, key to the security of all this is making SURE that ProxyRequests is set to Off. Open proxy servers are bad news for you and the tubes as a whole. :-)
Default: ProxyRequests Off
What did I do wrong?
First, thanks for the tutorial. One thing I got lost on was setting up datasources in the railo admin. It took a while, but something like this worked, which makes sense: http://localhost:8080/railo-context/admin/web.cfm?action=services.datasource
But I'm keen to learn how you might set things up yourself so that you have a better way to access the railo admin. I definitely got confused by the web vs server admins, but I can see how one might chose to set this up a number of different ways. In that light, I love to read more on how you're set up to run multiple sites, and administer railo either at the server or site level like that.


