Skip to content

Using Squatting with reverse proxy (Apache)

December 23, 2008

OK so you’ve just developed your first Squatting (On::Continuity) app and you now want to put it live on your main website/webserver.   So how do you do this?

Well a good seamless & scalable choice is using a Reverse Proxy.   This allows us to map a URL straight to a running Squatting app without too much fuss (famous last words!)

For this exercise I’ve used Apache (2.2) and with a bit trail & error I got below to work for me.

First off we need to switch on reverse proxy.   You will need to following in your httpd.conf file….

    ProxyRequests Off

    <Proxy *>
        Order deny,allow
        Allow from all

Now we want to make it point to our Squatting app….

    <VirtualHost *:80>
      DocumentRoot "/var/www/vhosts/"

      ProxyPass /demo/ http://localhost:4234/demo/
      ProxyPassReverse /demo/ http://localhost:4234/demo/

Now any requests to are “forwarded” on to your Squatting app running on port 4234.

You may notice that I put a trailing /demo/ on the proxy. This is because the Squatting app is launched via this script….

#!/usr/bin/env perl

use Demo 'On::Continuity', 'With::AccessTrace';
Demo->relocate( '/demo' );
Demo->continue(port => 4234);

I found this helped the webserver map back to the proxy when requests were made by the browser (eg. I’m sure there must be another (better?) way but this did work best for me despite endless fiddling with ProxyPass* & RewriteRules ;-(

Restart Apache & start above script in your Squatting app directory and you should find it is now accessible at That is except for any static content u had ;-(

Apache is better suited for pushing out static content so its best to let it deal with this by putting static files somewhere under its document root. However this did present a “best practise” problem between Continuity serving static files during testing and going live with Apache.

My approach to this was to prefix all static URI with “demohtml” using following code in

package Demo;
use strict;
use warnings;
use base 'Squatting';

    our %CONFIG = (

        static => '/demohtml',
        TT => {
            config   => { INCLUDE_PATH => './tt' },
            postfix  => '.tt',
            site_tit => 'Demo',


use Demo::Controllers;
use Demo::Views;

# static file handling
sub continue {
    my $app = shift;
        docroot => "./www", 
        staticp => sub { 
            $_[0]->url =~ m/\.(jpg|jpeg|gif|png|css|ico|js|swf)$/ 


Then I would have the following in my View & template(s)…..

# in Demo::Views (good place is in "_" default template)
$v->{ Static } = $Demo::CONFIG{ static };

# and then in TT file(s)....
<link rel="stylesheet" href="[% Static %]/demo.css" type="text/css" media="screen" title="Demo" />

Therefore the above now appears in the HTML like so…

    <link rel="stylesheet" href="/demohtml/demo.css" type="text/css" media="screen" title="Demo" />

This Demo’s static content lives under ./www/demohtml/ in the Squatting app directory so works fine with Continuity during testing. I then sym-linked ./www/demohtml under the Apache document root so that u can see it @

So Bob’s your Uncle… u should now find your Squatting app working via reverse proxy as u would expect it to 😉


Further reading… Have a look at App::VW to manage the Squatting apps.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: