Learnosity Logo
Learnosity Banner Image

Railo on Tomcat revisited - mod_proxy

I've been doing some more work on configuring railo to work flexibly in the numerous different environments we work in, and also making it simpler to set up.

To that end I investigated the use of mod_proxy for linking it to apache instead of mod_jk.

Advantages of this approach are:

  • Simple - communications are in plain http
  • Flexible - Load balancing can be easily added at the apache layer
  • Simple - No compiling mod_jk

Here are the basic install instructions for Railo/Tomcat/Apache on Ubuntu.

Download & Install Tomcat

Download tomcat and extract content:

tar xvzf apache-tomcat-6.0.26.tar.gz

Move Tomcat to a more appropriate place:

sudo mv apache-tomcat-6.0.26 /opt/tomcat

Download Railo

Download Railo custom version jars file

Extract and move into Tomcat lib directory:

tar zxvf railo-3.1.2.001-jars.tar.gz
sudo mv railo-3.1.2.001-jars/* /opt/tomcat/lib

Make Tomcat and Railo work together by modifying the web config file:

sudo nano -w /opt/tomcat/conf/web.xml

add the following inside the <web-app> element:

<servlet>
<servlet-name>CFMLServlet</servlet-name>
<servlet-class>railo.loader.servlet.CFMLServlet</servlet-class>
<init-param>
<param-name>configuration</param-name>
<param-value>{web-root-directory}/WEB-INF/railo/</param-value>
<description>Configuraton directory</description>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfc</url-pattern>
</servlet-mapping>

add the following inside <welcome-file-list> element:

<welcome-file>index.cfm</welcome-file>
<welcome-file>index.cfml</welcome-file>

Start up tomcat:

/opt/tomcat/bin/startup.sh
Once this is done you should be able to access the railo admin by going to the following URL:

Back to Tomcat

To test our Railo installation, let's create a test site by adding a new virtual host in both Tomcat and Apache. We do this by modifying Tomcat server.xml file (/opt/tomcat/conf/server.xml )
<Host name="testsite.railo" appBase="webapps">
<Context path="" docBase="/vhosts/testsite.railo/www"/>
</Host>

Linking with Apache via Mod Proxy

Ensure the modules proxy and proxy_http are enabled. On Ubuntu this is done as follows:

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo /etc/init.d/apache2 restart

Create vhost

Now we need to create a virtual host entry in Apache as well:
<VirtualHost *:80>
DocumentRoot /vhosts/testsite.railo/www
ServerName testsite.railo
DirectoryIndex index.cfm
   #Proxy .cfm requests to railo
   <IfModule mod_proxy.c>
      <Proxy *>
      Order deny,allow
      Allow from all
      </Proxy>
      ProxyPassMatch ^/(.*\.cfm)$ http://testsite.railo:8080/$1
      ProxyPassReverse / http://testsite.railo:8080/
   </IfModule>

   #Deny access to admin except for local/portforwarded clients
   <Location /railo-context/>
      Order deny,allow
      Deny from all
      Allow from 127.0.0.1
   </Location>
</VirtualHost>

This tells apache to forward all requests for CFM files to the railo instance.

Finally restart apache and railo and you should be good to go.

sudo /opt/tomcat/bin/shutdown.sh
sudo /opt/tomcat/bin/startup.sh
sudo /etc/init.d/apache2 restart

Upcoming book review - Tomcat 6 Developer's Guide

I've just received a copy of the Tomcat 6 Developer's Guide from packt publishing to review.

It's nice timing as I've been working with Tomcat 6 a bit lately and in the new year plan to move some of our production systems over to running Railo on top of Tomcat.

After the extremely busy year Learnosity has had I'm looking forward to reading a few books over the break and coming back in the New Year with lots more ideas and technology to implement.

Chinese characters not working cfdocument for PDF exports - fixed

I've just spent quite a few hours grappling with an annoying PDF export issue where the font's were not displaying correctly. This is on a CFMX 7 (7.0.2) on Ubuntu Linux system.

All the DB storage and application was using UTF8 throughout, but the PDF exports were showing nothing when they should have been showing Chinese characters.

To fix this up you need to do the following:

1. Need fonts installed on system:

sudo apt-get install ttf-arphic-bsmi00lp ttf-arphic-gbsn00lp

2. Need fonts installed in CFAdmin

  • Go to CFAdmin and Font Management
  • Select directory /usr/share/fonts/truetype/arphic
  • Select "Add" and you should see 2 new fonts added.

3: CFdocument Hotfix for CF7.0.2

The CFDocument hotfix for 7.0.2 provides some essential fixes and makes this work - Follow the instructions to install: http://kb2.adobe.com/cps/402/kb402093.html

Configure cffont.properties file

The final step is to set the cffont.properties file so that it will check additional font sets for any characters it doesn't know about - i.e. Chinese characters. Each line in the file is like a CSS font-family rule, i.e. it will start at the left and look for the correct font to render the text. I appended the two extra font names to ensure they are checked, so the file looks like this:

defaultbasefont=
dialog=Arial, Helvetica, AR PL SungtiL GB,AR PL Mingti2L Big5
dialog.bold=Arial Bold, Helvetica-Bold, AR PL SungtiL GB,AR PL Mingti2L Big5
dialog.italic=Arial Italic, Helvetica-Oblique, AR PL SungtiL GB, AR PL Mingti2L Big5
dialog.bolditalic=Arial Bold Italic, Helvetica-BoldOblique, AR PL SungtiL GB, AR PL Mingti2L Big5
dialoginput=Courier New, Courier, AR PL SungtiL GB, AR PL Mingti2L Big5
dialoginput.bold=Courier New Bold, Courier-Bold, AR PL SungtiL GB, AR PL Mingti2L Big5
dialoginput.italic=Courier New Italic, Courier-Oblique, AR PL SungtiL GB, AR PL Mingti2L Big5
dialoginput.bolditalic=Courier New Bold Italic, Courier-BoldOblique, AR PL SungtiL GB, AR PL Mingti2L Big5
serif=Times New Roman, Times-Roman, AR PL SungtiL GB, AR PL Mingti2L Big5
serif.bold=Times New Roman Bold, Times-Bold, AR PL SungtiL GB, AR PL Mingti2L Big5
serif.italic=Times New Roman Italic, Times-Italic, AR PL SungtiL GB, AR PL Mingti2L Big5
serif.bolditalic=Times New Roman Bold Italic, Times-BoldItalic, AR PL SungtiL GB, AR PL Mingti2L Big5
sansserif=Arial, Helvetica, AR PL SungtiL GB, AR PL Mingti2L Big5
sansserif.bold=Arial Bold, Helvetica-Bold, AR PL SungtiL GB, AR PL Mingti2L Big5
sansserif.italic=Arial Italic, Helvetica-Oblique, AR PL SungtiL GB, AR PL Mingti2L Big5
sansserif.bolditalic=Arial Bold Italic, Helvetica-BoldOblique, AR PL SungtiL GB, AR PL Mingti2L Big5
monospaced=Courier New, Courier, AR PL SungtiL GB, AR PL Mingti2L Big5
monospaced.bold=Courier New Bold, Courier-Bold, AR PL SungtiL GB, AR PL Mingti2L Big5
monospaced.italic=Courier New Italic, Courier-Oblique, AR PL SungtiL GB, AR PL Mingti2L Big5
monospaced.bolditalic=Courier New Bold Italic, Courier-BoldOblique, AR PL SungtiL GB, AR PL Mingti2L Big5

The cffont.properties file is located in /opt/jrun4/servers/{instance name}/cfusion.ear/cfusion.war/WEB-INF/cfusion/lib on the jrun multiserver version.

5. Restart CF

Once you restart CF you documents should be coming out with their Chinese fonts intact.

I'm sure there are additional fonts to add to get it working natively with all the other asian languages, so I'll add to this as and when I need/discover them. Please feel free to post a comment if you find any more font's that should be added to the list.

Installing Railo on Tomcat via Apache on Leopard - Step by Step

After a bit of fiddling and head scratching I managed to install Railo on Tomcat via Apache on my laptop running on OS X 10.5.6.

Tomcat

Firstly, download Tomcat 6

extract content:

tar xvzf apache-tomcat-6.0.18.tar.gz

Move Tomcat to a more secure place:

sudo mv apache-tomcat-6.0.18 /usr/local/tomcat

Railo

Download Railo custom version

extract and move into Tomcat lib directory:

tar zxvf railo-3.0.2.001-jars.tar.gz
sudo mv railo-3.0.2.001-jars/* /usr/local/tomcat/lib

Make Tomcat and Railo work together by modifying the web config file:

sudo nano /usr/local/tomcat/conf/web.xml

add the following inside the <web-app> element:

<servlet>
<servlet-name>CFMLServlet</servlet-name>
<servlet-class>railo.loader.servlet.CFMLServlet</servlet-class>
<init-param>
<param-name>configuration</param-name>
<param-value>{web-root-directory}/WEB-INF/railo/</param-value>
<description>Configuraton directory</description>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfc</url-pattern>
</servlet-mapping>

add the following inside <welcome-file-list> element:

<welcome-file>index.cfm</welcome-file>
<welcome-file>index.cfml</welcome-file>

Apache

Leopard OS comes with Apache 2, so you don't have to worry about installing it. However, you need to download The Apache Tomcat Connector source code.

Next you need to compile the source so that the resulting binary file is compatible with your Intel Mac architecture. I got this from Eric Rank's blog

cd into tomcat source:

cd tomcat-connectors-1.2.27-src/native

Edit the apache-2.0/Makefile.apxs.in file.

Replace

mod_jk.la:
$(APXS) -c -o $@ -Wc,"${APXSCFLAGS} ${JK_INCL}" "${JAVA_INCL}" "${APXSLDFLAGS}" mod_jk.c ${APACHE_OBJECTS}

with:

mod_jk.la:
$(APXS) -c -o $@ -Wc,"${APXSCFLAGS} -arch x86_64 ${JK_INCL}" "${JAVA_INCL}" "${APXSLDFLAGS} -arch x86_64 " mod_jk.c ${APACHE_OBJECTS}

configure the build files:

./configure --with-apxs=/usr/sbin/apxs

now go into apache-2.0 directory and build:

cd apache-2.0
make -f Makefile.apxs

Finally install

sudo make install

Now specify the connection between Apache and Tomcat. To do this you need to create workers.properties file. I created mine in /etc/apache2.

sudo nano /etc/apache2/workers.properties

Paste the following:

worker.list=default

worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

Now we need to modify the Apache httpd.conf file:

sudo nano /etc/apache2/httpd.conf

Enable The Apache Tomcat Connector:

LoadModule jk_module libexec/apache2/mod_jk.so

Underneath that tell Apache where your workers.properties file is located and add some logging info (could be useful):

# Mod_jk settings
JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel debug
DirectoryIndex index.html index.htm index.cfm index.cfml

Back to Tomcat

To test our Railo installation, let's create a test site by adding a new virtual host in both Tomcat and Apache. We do this by modifying Tomcat server.xml file (/usr/local/tomcat/conf/server.xml )
<Host name="railo.local" appBase="/Users/marko/Sites/railo/www">
<Context path="" docBase=""/>
</Host>

Apache

Now we need to create a virtual host entry in Apache as well:
<VirtualHost *:80>
JkMount /*.cfm default
ServerName railo.local
DirectoryIndex index.cfm
</VirtualHost>

JkMount /*.cfm default
Tells mod_jk to use the connector specified in your workers.properties file when it encounters a .cfm extension.

Important

Notice that in my Apache VirtualHost entry there is no DocumentRoot. I originally had it in there and it was breaking my Apache-Tomcat connection. It was driving me mad. It's probably because document root is already specified in /usr/local/tomcat/conf/server.xml.

One last thing, to start your Tomcat server type in this command:

/usr/local/tomcat/bin/startup.sh

shut down

/usr/local/tomcat/bin/shutdown.sh

My assumption is that the above steps would be very similar on other operating systems as long as you use the correct file paths.

Good luck :-)

Marko

Railo Useful links

I've been doing some research on Railo with a view to moving some of our sites to using it. I've found a few useful links along the way:

My evaluations of Railo are so far so good, with performance being one of the key issues and for our application I've seen performance 30% faster than CF7 and 25% faster than CF8.

If I find any major issues or benefits I'll post them here.

Cheers, Mark