[Dancer-users] Dancer, Plack, plain old CGI and mod_rewrite

Alexis Sukrieh sukria at sukria.net
Thu Mar 11 09:29:57 CET 2010


Hi,

Le mercredi 10 mars 2010 à 14:49 +0100, icovnik a écrit :
> Hi,
> 
> I'm trying to set up a simple app, but unfortunately, it should run as
> old CGI script under Apache on Linux.
> The CGI script is reachable via http://server/appdir/script.cgi. I
> have set appdir/.htaccess like this:
> 
> RewriteEngine On
> RewriteRule ^(.*)$ script.cgi
> 
> The RewriteRule should be probably something like this:
> 
> 
> RewriteRule ^(.*)$ script.cgi?$1

Not really, the rewrite rule should not path the path_info as a
QUERY_STRING.

> [...]
> Please assume that I am unable to run the application under FCGI or
> mod_perl. The Dancer's http server works but I need to make it work on
> our server... so... as plain CGI.

What you want to deploy is supported by Dancer with Plack, that works,
and I'm going to give you a working example (which will then be added to
Dancer::Deployment).

This is how I deploy my test applications:

I have a Virtualhost that matches *:80 which provides a bucnh of Dancer
apps served within their own directories. This way I can access "AppFoo"
with http://localhost/AppFoo/ (If understand you well, this is what you
want).

The following example provides /App1/ served by CGI and /App2/ served by
FastCGI.

Here is all that you need to get this working:

<VirtualHost *:80>
        ServerName localhost

        # This is the root directory of all the apps
        DocumentRoot "/PATH/TO/YOUR/ROOTDIR"  

        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f

        <Directory "/PATH/TO/YOUR/ROOTDIR">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
                AddHandler cgi-script .cgi
                AddHandler fastcgi-script .fcgi
        </Directory>

        RewriteRule /App1(.*)$ /App1/public/dispatch.cgi$1 [QSA,L]
        RewriteRule /App2(.*)$ /App2/public/dispatch.fcgi$1 [QSA,L]
</VirtualHost>

Please note that the RewriteRule does not use a question mark, the
rewritten path should look (internally) like the following:

/App1/foo/bar => /App1/public/dispatch.cgi/foo/bar

request->path will then be - as you can expect - "/foo/bar"

This works perfectly well on my box, it should work on yours ;)

Good luck.

-- 
Alexis Sukrieh



More information about the Dancer-users mailing list