May 2014

Gavin Pickin

Multi CFML Engine Install - Extracting the Railo Connector for Apache

CFML Server, Server Admin

We are going to setup apache with virtual hosts to deliver multiple CFML engines.
To do so, we need to setup the cfml engine adapters / connectors, 1 by 1, and remove their connector code from the main httpd.conf and then include that connector string in the Vhosts themselves, while leaving any LOAD MODULE code in the main httpd.conf, because we only want to load the module once, and because you cannot load modules in a Virtual Host. This way, we can designate which sites use what connector. Lets do Railo.

Apache Test File

To test we're going to use a page called index2.cfm
Go to our apache root, /home/www/default (in our case)
nano index2.cfm

<h1>Apache Root</h1>
<cfdump var="#server#">

[ Enter ]

No, lets try the page

Apache displayed the source of the page, because its not prepared to server the CFML in it, it just shows it.

Ok, so now, we're going to setup one of our CFML Engines.

First, we will connect Railo A

Mark Drew mentioned a couple of different ways to connect to railo in the google groups

Simple way, just proxy to the AJP port (remember when we installed we set 3 different ports)
<Proxy *>
Allow from
ProxyPreserveHost On
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://localhost:8021/$1$2

When you install Railo and ask it to add the connector, it adds the following code to the https.conf file
This depends on if you select to install the connector.

<IfModule mod_proxy.c>
<Proxy *>
Allow from
ProxyPreserveHost On
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$$1$2
ProxyPassMatch ^/(.+\.cfchart)(/.*)?$$1$2
ProxyPassMatch ^/(.+\.cfres)(/.*)?$$1$2
ProxyPassMatch ^/(.+\.cfml)(/.*)?$$1$2
# optional mappings
#ProxyPassMatch ^/flex2gateway/(.*)$$1
#ProxyPassMatch ^/messagebroker/(.*)$$1
#ProxyPassMatch ^/flashservices/gateway(.*)$$1
#ProxyPassMatch ^/openamf/gateway/(.*)$$1
#ProxyPassMatch ^/rest/(.*)$$1
ProxyPassReverse /

PerlRequire /opt/railoa/tomcat_connectors/mod_cfml/
PerlHeaderParserHandler mod_cfml
PerlSetVar LogHeaders false
PerlSetVar LogHandlers false
PerlSetVar CFMLHandlers ".cfm .cfc .cfml"

What connector should we use?

Lets go with the first one, since it will help us when we go to CLUSTER our Railo Instances.
Add the following code (assuming railoa is running and on 8021)

Use CTRL V repeated until you're at the bottom of the page.
Right above the Includes we added, insert this code.
<Proxy *>
Allow from
ProxyPreserveHost On
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://localhost:8021/$1$2

Save the https.conf

[ Enter ]

To use the AJP adapter, you need to make sure the module is loaded.
LoadModule proxy_ajp_module modules/


Restart apache,
service httpd restart
and run our test page http://[machinename]/index2.cfm
You will get a missing include railo error. Why?
When apache passes the request to Tomcat, tomcat translates that request into its own set of websites. Remember tomcat is a full fledged web server itself, some use it in production, but most people still recommend apache… although a lot are moving to nginx (pronounced EngineX).
Because we want to use ACF9 and Railo and a Railo Cluster, it makes perfect sense to use apache to serve non cfml files, and load balance the cfml requests too.
Lets try something else.
Lets try http://[machinename]/test.cfm
Apache doesn't have a test.cfm… in its root… but Railo does, so what do you think happens?

Apache 404?
Nope, since Apache knows it is CFML, Apache doesn't check to see if the file exists, it just passes the request to Tomcat… and it shows the page we first created in the previous Article installing Railo.

If you go to http://[machinename]:8501/filename.html Tomcat is handling all the requests… images, css, pdf, anything in your webpage.

When you go to http://[machinename] you are using port 80… so Apache handles everything, except CFML, when the https.conf or vhosts are setup right.
Detour over.

So now, lets make index2.cfm in the railo default root.
<h1>Railo A</h1> <cfdump var="#server#"> will suffice for now.

You should see Railo's Dump Stylings, and cold fusion.rootdir = /opt/railoa/tomcat/webapps/root
Copy out that part of the conf and save it as

Multi Instances of Railo

Lets edit the ajp port, and test Railob with port 8022
Make the same equivalent index2.cfm in the railob's path, and refresh the browser to test it.
copy out railob

<Proxy *>
Allow from
ProxyPreserveHost On
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://localhost:8022/$1$2

<Proxy *>
Allow from
ProxyPreserveHost On
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://localhost:8023/$1$2

Railo Cluster
We'll look at this another time, but basically, you just set all the ajp hosts for all the tomcat instances you want to use in the cluster… and it proxies the request.
There are more settings to tweak, but this will work for now.

<Proxy balancer://mycluster>
BalancerMember ajp://localhost:8021/ route=node1 loadfactor=1
BalancerMember ajp://localhost:8022/ route=node1 loadfactor=1
ProxySet lbmethod=byrequests
ProxyPreserveHost On
ProxyPassMatch ^/(.*\.cf[cm]/?.*)$ balancer://mycluster/$1 nofailover=On

Restart Apache
service httpd restart
Now view http://[machinename]/index2.cfm
Now, refresh several times, you should see a 50/50 split approximate of Railo A's page, and Railo B's page. No Railo C, because we didn't include that BalanceMember.
Ok, copy out the code… and put that aside.

Ok, the easy part is done… ready for the tough stuff?
Now, lets GET the COLDFUSION config.

Lets do that in another post :)


Blog Search