NAME

VERSION

version 0.159002

DESCRIPTION

Dancer has been designed to be flexible, and this flexibility extends to your choices when deploying your Dancer app.

Running as a cgi-script (or fast-cgi) under Apache

In providing ultimate flexibility in terms of deployment, your Dancer app can be run as a simple cgi-script out-of-the-box. No additional web-server configuration needed. Your web server should recognize .cgi files and be able to serve Perl scripts. The Perl module Plack::Runner is required.

Start by adding the following to your apache configuration (httpd.conf or sites-available/*site*):

Here, the mod_rewrite magic for Pretty-URLs is directly put in Apache's configuration. But if your web server supports .htaccess files, you can drop those lines in a .htaccess file.

To check if your server supports mod_rewrite type apache2 -l to list modules. To enable mod_rewrite on Debian or Ubuntu, run a2enmod rewrite. Place following code in a file called .htaccess in your application's root folder:

To test if content compression works, trace the HTTP request and response before and after enabling this middleware. Among other things, you should notice that the response is gzip or deflate encoded, and contains a header Content-Encoding set to gzip or deflate.

Creating a service

You can turn your app into proper service running in background using one of the following examples:

Using Ubic

Ubic is an extensible perlish service manager. You can use it to start and stop any services, automatically start them on reboots or daemon failures, and implement custom status checks.

A basic PSGI service description (usually in /etc/ubic/service/application):

Running stand-alone behind a proxy / load balancer

Another option would be to run your app stand-alone as described above, but then use a proxy or load balancer to accept incoming requests (on the standard port 80, say) and feed them to your Dancer app.

This could be achieved using various software; examples would include:

Using Apache's mod_proxy

You could set up a VirtualHost for your web app, and proxy all requests through to it:

Using balance

It could be used simply to hand requests to a standalone Dancer app. You could even run several instances of your Dancer app, on the same machine or on several machines, and use a machine running balance to distribute the requests between them, for some serious heavy traffic handling!

To listen on port 80, and send requests to a Dancer app on port 3000:

balance http localhost:3000

To listen on a specified IP only on port 80, and distribute requests between multiple Dancer apps on multiple other machines:

Running from Apache under appdir

If you want to deploy multiple applications under the same VirtualHost (using one application per directory, for example) you can use the following example Apache configuration.

This example uses the FastCGI dispatcher that comes with Dancer, but you should be able to adapt this to use any other way of deployment described in this guide. The only purpose of this example is to show how to deploy multiple applications under the same base directory/virtualhost.

Of course, if your Apache configuration allows that, you can put the RewriteRules in a .htaccess file directly within the application's directory, which lets you add a new application without changing the Apache configuration.

Running on lighttpd (CGI)

To run as a CGI app on lighttpd, just create a soft link to the dispatch.cgi script (created when you run dancer -a MyApp) inside your system's cgi-bin folder. Make sure mod_cgi is enabled.