/deployment/apache reverse proxy

Deploying Catalyst apps with Apache and Starlet

Use Apache to server static content and proxy requests to your standalone app.

Configure Apache 2

Ensure you have the mod_proxy module installed and loaded. Then configure your virtual host:

<VirtualHost *:80>
Alias /static "/srv/http/cat-app/root/static"
<Proxy *>
    Order deny,allow
    Allow from all
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /static !
ProxyPass / http://localhost:5000/ keepalive=On
ProxyPassReverse / http://localhost:5000/
RequestHeader set X-Forwarded-HTTPS "0"

Run Catalyst app with Plack and Starlet

Next start the Catalyst app listening on the same port that you configured Apache to proxy to:

$ cpanm Starlet
$ cd cat-app
$ plackup -I lib -s Starlet --max-workers --env deployment \
    --port=5000 script/

Be sure the app loads Plack::Middleware::ReverseProxy. If you use the server script provided by Catalyst, it will automatically load it. If you create your own .psgi file, load the default middleware:

my $app = Cat::App->apply_default_middlewares( Cat::App->psgi_app );


Alternatively, you can use Server::Starter to help manage the server daemon and provide graceful restarts when hot deploying:

$ cpanm Server::Starter
$ start_server --port=5000 --pid-file=... --status-file=... -- \
    plackup -I lib -s Starlet --max-workers --env deployment \

# later on....
$ start_server --pid-file=.... --status-file=... --restart

--restart will start the new version of your server, switch over the incoming requests, and then kill off the old processes. Result: seamless hot deployment.