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>
ServerName www.myserver.com
Alias /static "/srv/http/cat-app/root/static"
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /static !
ProxyPass / http://localhost:5000/ keepalive=On
ProxyPassReverse / http://localhost:5000/
RequestHeader set X-Forwarded-HTTPS "0"
</VirtualHost>

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/cat-app_server.pl

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 );

Server::Starter

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 \
    script/cat-app_server.pl

# 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.

My tags:
 
Popular tags:
 
Powered by Catalyst
Powered by MojoMojo Hosted by Shadowcat - Managed by Nordaaker