Moving my Catalyst Apps from Apache/FCGI to Nginx/Starman

Recently I had to move all my projects to a new server and decided to give Nginx and Starman a chance.

The Nginx config is rather simple.

my Catalyst Application is located at /var/www/MyApp

server {
    listen 80;
    server_name *;

    location / {
      include /etc/nginx/proxy_params;
      proxy_pass http://unix:/var/www/MyApp/myapp.socket:/;

    location /static {
      root /var/www/MyApp/root;
      expires 30d;

Nginx expects the Catalyst Application to listen on the socket /var/www/MyApp/myapp.socket.

Here is my initd script that takes care of starting and stopping the starman processes. (/var/www/MyApp/myapp.starman.initd)

#!/usr/bin/env perl
use warnings;
use strict;
use Daemon::Control;

my $app_home = '/var/www/MyApp';
my $program  = '/var/www/perl5/perlbrew/perls/perl-5.16.2/bin/starman';
my $name     = 'MyApp';
my $workers  = 1;
my $pid_file = $app_home . '/';
my $socket   = $app_home . '/myapp.socket';

    name        => $name,
    lsb_start   => '$nginx',
    lsb_stop    => '$nginx',
    lsb_sdesc   => $name,
    lsb_desc    => $name,
    path        => $app_home . '/myapp.starman.initd',

    user        => 'www-data',
    group       => 'www-data',
    directory   => $app_home,
    program     => "$program -Ilib myapp.psgi --workers $workers --listen $socket",

    pid_file    => $pid_file,
    stderr_file => $app_home . '/myapp.out',
    stdout_file => $app_home . '/myapp.out',

    fork        => 2,

Check out Daemon::Control, it's a really helpful CPAN module that eases the creation of init scripts. Let's create the initd script.

./myapp.starman.initd get_init_file > /etc/init.d/cat-myapp

You want the starman processes to survive a reboot, so let's install to runlevels

update-rc.d cat-myapp defaults

Now reload Nginx and start your starman processes and you should be good to go.

I just started using this kind of config, so any problems wouldn't surprise me too much.


Great to read that more people are deciding towards the nginx/Starman combo. Recently we started moving the first Catalyst applications to new virtual machines and also used nginx and Starman.

We added a couple of things for optimization and convenience:

* CSS and JS are each combined into a single file at deployment time. These files are delivered statically by nginx
* Thumbnails based on uploaded files are cached when first requested and delivered by nginx if available
* Static resources like images are also directly delivered by nginx
* We added a maintenance mode presenting a maintenance page to most users and allows to test the backend for assorted people. We found nginx's geo module being a great way to do this.

In order to avoid to install perl modules globally, we decided to use the usual (but ugly) case-statement-driven /etc/init.d script as a shell script instead of perl. But Daemon::Control results in a much shorter and more maintainable script. I think about borrowing your idea :-)

Any benchmarks? Difference in memory usage?

A followup on the stability of this setup would be nice...

I'm also trying to ditch Apache in some cases.

Hi Wolfgang,

I'd love to see a copy of your nginx config, can you post it on github or similar?

specifically how to serve css, js, etc via nginx and not hit starman


Leave a comment

About davewood

user-pic I like Toast.