I followed the instructions in the Dancer2 deployment guide for running as a cgi-script but I am getting HTTP 504 Gateway Time-out when I try to access my application in a browser. I am brand new to the world of PSGI/Plack so I could be way off in my diagnosis, but it looks like when I request

http://<hostname>/

from a remote host, dispatch.cgi starts up a server listening on port 3000 and then just sits there waiting for input until the request times out. Here's what I see in my Apache error log:

[Mon Nov 04 09:44:32 2013] [error] [client 128.117.20.57] [ip2map:30142]  core @2013-11-04 09:44:32> Registered Dancer2::Core::DSL__WITH__Dancer2::Plugin::Ajax=HASH(0x3414560) in /var/www/ip2map/public/../lib/ip2map.pm l. 3
[Mon Nov 04 09:44:32 2013] [error] [client 128.117.20.57] [ip2map:30142]  core @2013-11-04 09:44:32> Registered Dancer2::Core::DSL__WITH__Dancer2::Plugin::Ajax__WITH__Dancer2::Plugin::Database=HASH(0x3414560) in /var/www/ip2map/public/../lib/ip2map.pm l. 4
[Mon Nov 04 09:44:32 2013] [error] [client 128.117.20.57] >> Dancer2 v0.10 server 30142 listening on http://0.0.0.0:3000
[Mon Nov 04 09:44:32 2013] [error] [client 128.117.20.57] >> Dancer2::Plugin::Ajax (0.10)
[Mon Nov 04 09:44:32 2013] [error] [client 128.117.20.57] >> Dancer2::Plugin::Database (2.10)
[Mon Nov 04 09:45:32 2013] [warn] [client 128.117.20.57] Timeout waiting for output from CGI script /var/www/ip2map/public/dispatch.cgi
[Mon Nov 04 09:45:32 2013] [error] [client 128.117.20.57] Script timed out before returning headers: dispatch.cgi

Here is my Apache configuration (Apache v2.2.15):

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName mcmes21.cgd.ucar.edu
    ServerAlias mcmes21
    DocumentRoot /var/www/ip2map/public
    ServerAdmin mcarey@ucar.edu

    <Directory "/var/www/ip2map/public">
       AllowOverride None
       Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
       Order allow,deny
       Allow from all
       AddHandler cgi-script .cgi
    </Directory>

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /dispatch.cgi$1 [QSA,L]

    ErrorLog  /var/log/httpd/ip2map-error_log
    CustomLog /var/log/httpd/ip2map-access_log common
</VirtualHost>

Note that my application works fine when served with Starman via mod_proxy with the following Apache configuration:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName mcmes21.cgd.ucar.edu
    ServerAlias mcmes21

    DocumentRoot /var/www/ip2map

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass        / http://localhost:5000/
    ProxyPassReverse / http://localhost:5000/
</VirtualHost>

Does anyone know how I can get this working as CGI?

--Max