简体   繁体   English

当将Dancer2应用程序作为cgi-script运行时HTTP 504网关超时

[英]HTTP 504 Gateway Time-out when running Dancer2 app as cgi-script

I am trying to deploy a Dancer2 application as a cgi-script with Apache. 我正在尝试使用Apache将Dancer2应用程序部署为cgi脚本。 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. 我按照Dancer2部署指南中说明作为cgi脚本运行,但是当我尝试在浏览器中访问应用程序时,出现HTTP 504网关超时。

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 我是PSGI / Plack领域的新手,因此我可能无法接受诊断,但是看起来像当我要求时

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. 从远程主机, dispatch.cgi启动服务器监听端口3000,然后坐在那里等待输入,直到请求超时。 Here's what I see in my Apache error log: 这是我在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

Here is my Apache configuration (Apache v2.2.15): 这是我的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>

Note that my application works fine when served with Starman via mod_proxy with the following Apache configuration: 请注意,当使用以下Apache配置通过mod_proxy与Starman配合使用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>

Does anyone know how I can get this working as CGI? 有谁知道我怎样才能使它成为CGI?

Note: I also posted this question to the dancer-users mailing list yesterday. 注意:我昨天也将此问题发布到了舞者用户的邮件列表中。

Use the following to configure Apache to run a Dancer app using mod_perl. 使用以下命令配置Apache以使用mod_perl运行Dancer应用程序。 This is much faster than CGI. 这比CGI快得多。

  1. Install mod_perl, if not already installed: 安装mod_perl(如果尚未安装):

      sudo apt-get install libapache2-mod-perl2 
  2. Install Plack and Dancer, if not already installed: 如果尚未安装,请安装Plack和Dancer:

      sudo apt-get install libplack-perl sudo apt-get install libdancer-perl 
  3. Add the following to your site configuration within apache (usually within ../sites-available). 将以下内容添加到apache中的站点配置中(通常在../sites-available中)。 In the snippet below, I use /home/user/dancerapp as the absolute path to your dancer app, and 'dancerapp.com' as your server name. 在下面的代码段中,我使用/ home / user / dancerapp作为您的舞者应用程序的绝对路径,并使用“ dancerapp.com”作为您的服务器名称。 Be sure to change to your app: 确保更改您的应用程序:

      <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> 
  4. Remember to restart apache: 记住重新启动Apache:

      sudo /etc/init.d/apache2 restart 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM