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

Migrating CSS from Flex 3 to Flex 4

Having searched around for how to make CSS work when migrating to Flex 4 from Flex 3 and finding lots of incorrect namespace declarations I thought I'd blog this as a reminder to myself:

If you have a current Flex3 project and you are migrating to Flex4 you need to add the following lines at the top of your stylesheet.

This makes the default non-namespaced items in your stylesheet refer to the MX components. eg:

Button{fontSize:18;}
And to style up spark buttons you simply use:
s|Button{fontSize:18;}

Note there were lots of ones that I found that were wrong.

Do NOT use:

This info was sourced from the Flex SDK Wiki.

Flex 4 RSL's and how to not use them

Flex 4 allows and defaults to using Runtime Shared Libraries (RSL's).

These have advantages of making flash movies using them work very well, but they can also require more http requests the first time they are used, and are not good for application development with Northcode.

To turn them off you need to add the following compiler flag:

-static-link-runtime-shared-libraries=true

Thanks to Flex Butterflies and bugs for the info.

Split first name and last name with Openoffice/Excel

I've been dealing with a lot of spreadsheets of usernames recently and sometimes you get firstname and lastname in seperate columns, and sometimes in the same column.

If you get them in the same column but need them in two columns here are two little formulae to do it:

FullName | FirstName | Lastname |
Mark Lynch | =MID(A2,1,FIND(" ",A2,1)) | =MID(A2,FIND(" ",A2,1)+1,100) |
Which will look like:
FullName | FirstName | Lastname |
Mark Lynch | Mark | Lynch |
This basically seperates the string on the space between the names and puts it into each column

Cheers, Mark

MySQL 5.1 logging changes - Log to DB and runtime config

While browsing around the MySQL site last night I discovered a number of nice new features of mysql 5.1 that relate to logging.

These are:

  • Logging to DB instead of log files
  • Runtime configuration of logging.

Logging to DB instead of log files

Coming from a web development background rather than a sysadmin background I'm far more comfortable manipulating and analysing data using SQL. So to be able to log all the queries or just the slow queries for an application to the db during application development or load testing is a huge benefit.

To enable logging to DB you can add the following to your my.cnf

log_output = TABLE

The logs will be written to the 'slow_log' and 'general_log' tables in the mysql database.

Note - logging to tables has more overhead than logging to file, so would suggest using it primarily for development purposes.

Full details of the options are on the mysql manual on log tables

Runtime configuration of logging.

This allows you to turn on and off logging without restarting MySQL - which just saves a little bit of time and makes it much nicer for debugging problems.

To turn on the logging of all queries run:

SET GLOBAL general_log = 'ON';
And for just the slow query log:
SET GLOBAL slow_query_log = 'ON';

And to turn them both off use:

SET GLOBAL general_log = 'OFF';
SET GLOBAL slow_query_log = 'OFF';

If you also want to see queries not using indexes in the slow query log you can set the following variable:

SET GLOBAL log_queries_not_using_indexes = 'ON';

Hope it helps, Mark