Load balancing a Railo cluster using AWS

Lately I have been playing around with load balancing Railo in a cluster.  Before Amazon Web Services this would have been a fairly expensive proposition, but AWS makes managing instances mostly painless.  Here I will be using EC2 instances, but this setup will can apply to just about any configuration.

The minimal requirements for this exercise will be to have three instances running.  First I created two instances of 64-bit Amazon Linux running configured with a basic Railo setup using the VivioTech installers and Apache as the front end.  I already have an AMI image created so I can easily create identically configured Railo instances with the click of a button.

Next we need to configure an instance to handle load balancing to each of our Railo instances and for this I will be using Nginx.   First, create a clean, new instance of Amazon 64-bit linux and SSH into the instance.  Amazon Linux uses the yum package manager so installing Nginx is as easy as:

yum install nginx

Once Nginx is installed, we just need to edit the config file and add in a few lines.  You can find the configuration file in /etc/nginx/nginx.conf.

# HTTP Core Module
#   http://wiki.nginx.org/NginxHttpCoreModule

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    upstream balancer {
        server 10.x.x.1;
        server 10.x.x.2;

    # The default server
    server {
        listen       80;
        server_name  _;

        location / {
            proxy_pass http://balancer;

        error_page  404              /404.html;
        location = /404.html {
            root   /usr/share/nginx/html;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;

    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;


This is the complete listing for the nginx.conf file.  This configuration is pretty much stock, I have removed the comments, added the upstream directive and modified the default server to proxy requests to the upstream provider named balancer.

This approach will evenly distribute requests to both machines.  You can add the hash;  ip_hash; directive to the top of  your upstream block to make the requests “sticky” and send requests to the same server behind the load balancer each time.

I have just started to using this setup so I am sure things will probably change as I start seeing what it can do. If you are interested in setting up a similar system to mess around with I highly recommend AWS.

Some helpful documentation: http://wiki.nginx.org/HttpUpstreamModule


CF Free Chat

Last year I wrote a simple chat system for ColdFusion as a demo for a friend of mine.  It was very simple; a component on the backend acted as the main controller for storing the “message cache” and on the front end jQuery code polls the cfc at a set interval and updates the chat window.  Simple stuff.

I never really got much further than the proof-of-concept code because of time constraints and also not long after that Railo introduced messaging websocket gateways with push notification.   Needless to say, I started playing around with that an the original project just fell to the wayside and I really just forgot about the simple CFChat app.

Fast-forward to yesterday.  Jessica pinged me letting me know she had released a free chat app based loosely on my code called CF Free Chat.  Her version is much more polished with private messaging, user warns and user kicks, all easily configured through a settings file.  With a few CSS tweaks you can easily have a customized version up and running in no time.

This was originally the direction I was intending on going with the application if I had the time to write it.  If you are looking for something along these lines I would definitely suggest checking it out.