ColdFusion and Tomcat Web Server Conifguration
May 16, 2011 · 1 Comment
This is the second of my posts about working with ColdFusion and Tomcat. You can read the first post here.
When using JRun as the underlying JEE servlet container for ColdFusion, you get the advantage of "wsconfig"; the Web Server Configuration Tool.
This connecter is a little JAR file which effectively handles all the fun and games of hooking up ColdFusion with your web server. When you use a different servlet container, in our case Tomcat, you need get your hands dirty.
SIDE NOTE: With the next release of ColdFusion using Tomcat under the hood, I think it would be fairly safe to assume that the ColdFusion team will create a version of wsconfig to handle the configuration like it does now.
There are a number of ways to handle the communication between the web server and ColdFusion, and I'm going to concentrate here on how we do it using Apache. The obvious method that comes to mind is mod_proxy, but for a variety of reasons we're going to look at the AJP connector instead.
You'll most likely find that your Apache installation will already have mod_proxy_ajp enabled, but you can double check by opening up your httpd.conf file and searching for the proxy module, or by looking for a proxy_ajp.conf file in your conf.d directory (your OS X / Linux distribution may vary).
Knowing that AJP is installed, we can now configure Apache to talk to ColdFusion via Tomcat. I have individual "conf" files for each of my Apache Virtual Hosts. As such, let's create a file in our conf.d directory called andyallan.conf Populate andyallan.conf with:
<VirtualHost *:80>
ServerName dev.andyallan.com
# We need to specify the Document Root as we are only proxying .cf* files to Tomcat, therefore keeping
# all static files served by Apache
DocumentRoot /opt/apache-tomcat-7.0.11/webapps/cfusion/andyallan/wwwroot
DirectoryIndex index.cfm
<Location />
Order allow,deny
Allow from All
</Location>
# Only allow proxing from 127.0.0.1
<Proxy *>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Proxy>
# We need the ProxyPreserveHost if we are using multiple VHosts
ProxyPreserveHost On
# Only Proxy .cfc and .cfm files
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://localhost:8009/cfusion/andyallan/wwwroot/$1$2#
# Need these two lines to maintain sessions
ProxyPassReverseCookieDomain / /
ProxyPassReverseCookiePath / /
# Configure logging
ErrorLog /var/log/httpd/andyallan-error.log
CustomLog /var/log/httpd/andyallan-access.log common
</VirtualHost>
To test that I can now access my site dev.andyallan.com without worrying about context roots, ports, etc, I simply drop an entry into my local hosts file and then fire the URL up in my browser.
Using a proxy will mess up some CGI variables and I'll touch on them in the next post.
For more information on AJP and the various proxy rules, check out:
Tags: ColdFusion · Tomcat

1 response so far ↓
1 Stephen Moretti // Jun 3, 2011 at 10:47 PM
As much as possible I'd like to replicate my current set up so that I don't have do a complete refactor of how servers are set up etc etc.
The only problem I have right now is that the mod_proxy_ajp appears to mean that I would need to move every site that I host using Tomcat under the webapp folder. Is that right? or can I have a /sites/clientname folder, for example, as the document root and have tomcat process cfm/cfc files from those folders?
What's the difference between using mod_proxy_ajp which comes with apache httpd, as opposed to mod_jk which is developed and supplied via apache tomcat?
Two whole blog posts for you. ;)
Leave a Comment