4

总结:无法运行任何最简单的“Hello World”FastCGI 脚本,任何请求总是以超时终止。似乎服务器和 FastCGI 脚本之间根本没有通信(使用动态 FastCGI 脚本)。

环境

  • Ubuntu 精确版 (12.04)
  • 包裹apache2.2-bin
  • 包裹apache2-mpm-prefork
  • 包裹libapache2-mod-fastcgi
  • 包裹libfcgi-perl
  • 包裹python-flup
  • 多个站点配置为虚拟主机127.0.0.1
  • 存在一个/var/lib/apache2/fastcgi目录,由 拥有www-data,所有人(所有者、组和其他人)都可以读取
  • 存在一个/var/lib/apache2/fastcgi/dynamic由 拥有的目录,该目录www-data仅限于所有者(只读、可写和www-data仅可访问)
  • /var/lib/apache2/fastcgi/目录下存在inode/socket文件

FastCGI 相关配置:

该目录/etc/apache2/mods-enabled/包含对fastcgi.conffastcgi.load(mod_fastcgi已启用) 的引用。

该文件fastcgi.conf包含以下内容(保持不变,我没有编辑它):

<IfModule mod_fastcgi.c>
  AddHandler fastcgi-script .fcgi
  #FastCgiWrapper /usr/lib/apache2/suexec
  FastCgiIpcDir /var/lib/apache2/fastcgi
</IfModule>

中的相关配置文件/etc/apache2/sites-enabled/包含以下内容(关于 FastCGI 特定配置的其他任何地方都没有):

<DirectoryMatch /fcgi-bin>
   Options +ExecCGI
   <FilesMatch "^[^\.]+$">
      SetHandler fastcgi-script
   </FilesMatch>
</DirectoryMatch>

测试虚拟主机上的测试材料:

存在一个fcgi-bin/test-perl.fcgi其内容是(该文件可以被所有人执行,并且可以被所有者和组读取):

#!/usr/bin/perl

use CGI::Fast qw(:standard);
    $COUNTER = 0;
    while (new CGI::Fast) {
    print header;
    print start_html("Fast CGI Rocks");
    print
        h1("Fast CGI Rocks"),
        "Invocation number ",b($COUNTER++),
            " PID ",b($$),".",
        hr;
        print end_html;
    }

存在一个fcgi-bin/test-python.fcgi其内容是(该文件可以被所有人执行,并且可以被所有者和组读取):

#!/usr/bin/python

def myapp(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return ['Hello World!\n']

try:
    from flup.server.fcgi import WSGIServer
    WSGIServer(myapp).run()
except:
    import sys, traceback
    traceback.print_exc(file=open("errlog.txt","a"))

问题

虽然fcgi-bin/test-perl.fcgi和都fcgi-bin/test-python.fcgi在从命令行执行时正常运行,但在调用时似乎都不起作用,例如 ashttp://test.loc/fcgi-bin/test-perl.fcgihttp://test.loc/fcgi-bin/test-python.fcgi.

什么都没有发生,经过一段时间的延迟,我得到一个错误 500,并且 Apache 错误日志包含多个条目,如下所示:

[<date>] [error] [client <IP>] FastCGI: comm with (dynamic) server "/<…&gt;/fcgi-bin/<script>.fcgi" aborted: (first read) idle timeout (30 sec), referer: <referrer>
[<date>] [error] [client <IP>] FastCGI: incomplete headers (0 bytes) received from server "<…&gt;/fcgi-bin/<script>.fcgi", referer: <referrer>

我花了几个小时在网上搜索试图了解它为什么不起作用,最后决定放弃并在这里寻求一些帮助。

欢迎任何指针和检查列表。随意询问您可能认为相关或值得检查的任何缺失细节。

享受美好的一天。

- 编辑 -

问题更新

我自己对自己问题的回答中,我提到了一个奇怪的案例,事情看起来突然好起来了,没有任何理由。后来我发现这只是部分好。

在相同的虚拟主机中,使用完全相同的服务器配置,一些完全相同(并且具有完全相同的访问权限)的脚本会根据它们的位置而失败。

作为其余部分,以下是站点配置中的内容:

<DirectoryMatch /fcgi-bin>
   Options +ExecCGI
   <FilesMatch "^[^\.]+$">
      SetHandler fastcgi-script
   </FilesMatch>
</DirectoryMatch>

有了上述,只有脚本/fcgi-bin被处理为 FastCGI 脚本。但我在其他地方也有一些(仍在测试中):一进/cgi-bin一进/(即在public_html目录中)。为此,.htaccess包含以下条目:

Options +ExecCGI
AddHandler fastcgi-script .fcgi

因此,另外两个 FastCGI 脚本应该与 in 中的一样工作/fcgi-bin,但它们没有,并且在当时,它们总是以连接超时终止,就像第一个/fcgi-bin那样。

这让我觉得mod_fastcgi模块可能有问题(已知错误?其他?)。到目前为止,这个模块似乎是相当随机的。

-- 编辑 2 --

第一次编辑中的上述内容是我的错误:该组对其他脚本有误,它必须是www-data,但不是。有什么问题吗,请坚持我给出的答案,即尝试查看FastCgiConfig,看看它是否解决了任何问题,或者至少它是否支持超时选项。

4

3 回答 3

4

I will answer my own question, as it seems to be working now. However, the epilogue still looks weird.

Although the default configuration should be OK, I still wanted to review the “Module mod_fastcgi” document again. As I only wanted a dynamic FastCGI, I focused on the FastCgiConfig directive only, thus on purpose not going into FastCgiServer and FastCgiExternalServer directives.

As there was no FastCgiServer at all in the default fastcgi.conf file, I started to try to set‑up my own. For a first test, I wanted to use the -appConnTimeout option, at least to request the server to not wait so much long before it returns me an Error 500.

So I just added this in the site configuration (I did not touch fastcgi.cong), in the same file where virtual hosts are configured:

FastCgiConfig -appConnTimeout 2

This was to tell the server to wait no more than 2 seconds, instead of the 30 seconds it was waiting. I tried to invoked a FastCGI script to see if at least this configuration was working. I expected to get an error in a 2 seconds delay, but instead, the script ran without error.

What's weird, is that I then tried to remove this option, to check if it was just that addition which was just missing to make FastCGI scripts working. But after I commented‑out the option, it was still working, and the same after a full reboot.

Can't tell more, that looks weird, but this is the only thing I did, I did not edit anything else. I can just suggest people who may encounter a similar issue, to just try the above.

Sorry, if I can't explain what it did exactly. I really would like to know. It just working now, but I don't know why.

于 2013-03-22T07:46:26.250 回答
2
#############

fastcgi.conf FastCgiWrapper 关闭

于 2014-05-21T06:46:32.873 回答
0

peng.rl 的回答解决了我的问题。

我的 ceph radosgw 根本无法获得 apache 的输入。设置 FastCgiWrapper Off 后,我可以在 wireshark 中捕获数据。

于 2015-01-13T08:28:20.377 回答