Jun 04
Deploying Dancer apps with Apache2
While the Dancer documentation recommends deploying Dancer apps + Apache with Apache being configured as a proxy, I wanted to run my Dancer app as I was used to from CGI::Application applications, as simple cgi script.
This means I use the dispatch scripts located in /public, triggering them by the CGI interface of Apache with the help of mod_rewrite.
Okay, my two tips for people doing the same:
- Don't look at the examples for Apache, but look at the example for "running as cgi script"
- When you run the app via .cgi, use this rewrite rule:
RewriteRule ^(.*)$ /dispatch.cgi/$1 [QSA,L]
whereas when you run it as .fcgi, use this variation:
RewriteRule ^(.*)$ /dispatch.fcgi$1 [QSA,L]
Note the slight difference between the directly attached path under FastCGI and the / slash prepended version when running under unaccelerated CGI. Took me a few hours to find this one...
Also note that the slash version also works for FCGI. So if you intend to switch between fcgi and cgi (for development purposes) by changing the extension in your Apache config, use the slash version as it works with both.
An example VirtualHost config section or what needs to go into a .htaccess file:
<VirtualHost <YOUR-IP>:80>
ServerName www.example.com
ServerAlias example.comDocumentRoot /var/www/example.com/public
CustomLog /var/www/example.com/logs/access.log combined
ErrorLog /var/www/example.com/logs/error.log<Directory />
Options FollowSymLinks
Options -Indexes
AllowOverride None
Allow from all
</Directory># DirectoryIndex index.html
## Define the mod_rewrite rules for a Dancer app here,
## Or put this into a .htaccess file and remove the
## "AllowOverride None" directive above
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ /dispatch.fcgi/$1 [QSA,L]
</VirtualHost>