[Catalyst] Multiple applications (some cat based) on the same server

Peter Edwards peter at dragonstaff.co.uk
Fri Aug 26 08:31:36 GMT 2011

Hi Rod

On 26 August 2011 00:37, Roderick A. Anderson <raanders at cyber-office.net>wr=

> Preface.  Somehow my subscription was disabled due to too many bounces
> (which I don't see in my server logs but oh well) so sorry if this made it
> through but I never got any replies.
> Ditto. :-/

 I'm wondering how difficult (or if even possible) it is to have several

> applications, with two or more being cat based, running on the same
> httpd (Apache) server?
Sure, you need to run a reverse caching proxy front end server and proxy
different paths to different back ends.
Consider using middleware like Plack to make it easier if you want to change
your setup later.
Leo Lapworth gave a great talk at YAPC::EU in Riga about all this, have a
read through:

A lot depends on your volume of hits and how many users and whether there
are any special needs like large file downloads/streaming.
If, as I guess, it's fairly low usage then you can do it all on one server
with Apache2.
If it might need scaling, then use something like nginx or perlbal for the
frontend and use vhosts to split backend requests across different pools of
servers for different apps or media serving.

Say you want to be old school and use Apache2 as your front end lightweight
caching reverse proxy and also for your backends on a single server
then you do it by proxying different path parts to different servers
(this is what I'd have done back in the days before Plack was invented, now
you could use http://search.cpan.org/perldoc?Plack::App::Proxy)

if a URL starts /appfoo/  like  /appfoo/blah/blah/foo.pl?a=3D1&b=3D2  then =
to a localhost server running at port 9000   (old Perl app)
if a URL starts /appbar/ like /appbar/my/glorious/restful/app  then proxy to
localhost server running at port 9001   (Catalyst Perl app)
if a URL ends in .php like /somecms/edit.php?c=3D1&d=3D2   then proxy to
localhost server running at port 9002    (PHP CMS app)
otherwise serve static assets (.jpg, .html) directly from the frontend
caching Apache server

In that scenario you are running
- one lightweight frontend Apache2 to handle reverse proxying (make sure to
remove all unnecessary modules from its config to make it light as possible
on memory)
- one heavyweight backend Apache2 configured for Perl for your old Perl app
on port 9000
- one backend server, maybe using Starman server and Plack middleware, for
your Catalyst app on port 9001
- one heavyweight backend Apache2 configured for PHP for your PHP CMS on
port 9002

In Apache frontend you can set up reverse proxying with mod_proxy
ProxyPass /foo http://foo.example.com/bar
ProxyPassReverse /foo http://foo.example.com/bar
use mod_rewrite
 RewriteRule  ^/appfoo/(.*)$  http://localhost:9000/$1  [L]
 RewriteRule  ^/appbar/(.*)$  http://localhost:9001$1   [L]
 RewriteRule ^(*\.php*)$  http://localhost:9002$1  [NC,L]
(more at http://corz.org/serv/tricks/htaccess2.php)
you can use a different virtual host for each app and put the proxying
directives in separate VirtualHost blocks, i.e. <VirtualHost
phpcms.mycompany.com>...</VirtualHost> <VirtualHost appfoo.mycompany.com>

In your backend apps if you use Apache pick up the user's originating host
from environment variables
X-Forwarded-ForThe IP address of the client.X-Forwarded-HostThe original
host requested by the client in the Host HTTP request header.

Regards, Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110826/d2637=

More information about the Catalyst mailing list