我正在尝试将 Dancer2 应用程序部署为 Apache 的 cgi 脚本。我按照Dancer2 部署指南中的说明作为 cgi 脚本运行,但是当我尝试在浏览器中访问我的应用程序时出现 HTTP 504 Gateway Time-out。
我对 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>
请注意,当使用以下 Apache 配置通过 mod_proxy 与 Starman 一起服务时,我的应用程序可以正常工作:
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 工作?
注意:我昨天也将这个问题发布到了 dancer-users 邮件列表。