我正在尝试使用Apache将Dancer2应用程序部署为cgi脚本。我跟着instructions in the Dancer2 deployment guide作为cgi脚本运行但是当我尝试在浏览器中访问我的应用程序时,我得到HTTP 504网关超时。
我是PSGI / Plack世界的新手,所以我可以在诊断中离开,但看起来像我要求
http://<hostname>/
来自远程主机,dispatch.cgi
启动服务器侦听端口3000,然后只是坐在那里等待输入,直到请求超时。这是我在Apache错误日志中看到的内容:
[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
这是我的Apache配置(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>
请注意,我的应用程序在通过mod_proxy与Starman一起提供时使用以下Apache配置正常工作:
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>
有谁知道我如何才能将其作为CGI工作?
注意:我昨天也将这个问题发给了舞者用户邮件列表。
答案 0 :(得分:3)
使用以下命令配置Apache以使用mod_perl运行Dancer应用程序。这比CGI快得多。
安装mod_perl(如果尚未安装):
sudo apt-get install libapache2-mod-perl2
安装Plack and Dancer,如果尚未安装:
sudo apt-get install libplack-perl
sudo apt-get install libdancer-perl
将以下内容添加到apache中的站点配置中(通常在../sites-available中)。在下面的代码段中,我使用/ home / user / dancerapp作为舞者应用程序的绝对路径,并使用'dancerapp.com'作为您的服务器名称。请务必更改为您的应用:
<VirtualHost *:80>
ServerName dancerapp.com
DocumentRoot /home/user/dancerapp/public
<Location />
SetHandler perl-script
PerlResponseHandler Plack::Handler::Apache2
PerlSetVar psgi_app /home/user/dancerapp/bin/app.pl
SetEnv DANCER_ENVIRONMENT "production"
</Location>
<Perl>
use Plack::Handler::Apache2;
Plack::Handler::Apache2->preload("/home/user/dancerapp/bin/app.pl");
</Perl>
</VirtualHost>
请记住重启apache:
sudo /etc/init.d/apache2 restart