【发布时间】:2014-03-05 03:58:22
【问题描述】:
我正在尝试使用fastcgi_module 在 Apache2 (Apache/2.4.6 (Ubuntu)) 中运行 cgi 脚本。这是我设置的虚拟主机
<VirtualHost *:8080>
ServerName cgi.local
DocumentRoot /home/noobeana/CGI
<Directory /home/noobeana/CGI>
AllowOverride All
Order allow,deny
Allow from all
Require all granted
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
SetHandler fastcgi-script
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
这是我为运行测试而创建的 Perl 脚本(正确地 775'ed)(/home/noobeana/CGI/test.pl):
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello there!<br />\n";
Perl 可执行文件的路径确实是/usr/bin/perl,其他一切看起来都很好,但是当我在浏览器中打开http://cgi.local:8080/test.pl 时,脚本会永远运行——我必须停止Apache 才能强制退出。此外,print 正在输出到 Apache 的错误日志(而不是浏览器),只要脚本正在运行,它就会显示大量以下行:
[Fri Feb 07 10:24:54.059738 2014] [:warn] [pid 4708:tid 140365322880896] FastCGI: (dynamic) server "/home/noobeana/CGI/test.pl" started (pid 4771)
Content-type: text/html
Hello there!<br />
[Fri Feb 07 10:24:54.078938 2014] [:warn] [pid 4708:tid 140365322880896] FastCGI: (dynamic) server "/home/noobeana/CGI/test.pl" (pid 4771) terminated by calling exit with status '0'
[Fri Feb 07 10:24:59.663494 2014] [:warn] [pid 4708:tid 140365322880896] FastCGI: (dynamic) server "/home/noobeana/CGI/test.pl" restarted (pid 4773)
Content-type: text/html
Hello there!<br />
[Fri Feb 07 10:24:59.665855 2014] [:warn] [pid 4708:tid 140365322880896] FastCGI: (dynamic) server "/home/noobeana/CGI/test.pl" (pid 4773) terminated by calling exit with status '0'
我不确定这两个问题(print 未在浏览器中输出和脚本未终止)是否相关。
【问题讨论】:
-
CGI 和 FastCGI 真的很老派。您应该寻找现代 Perl 框架,例如 Dancer 和 Mojolicious
-
@dolmen:错误的二分法。 CGI 和 FastCGI 是接口,而不是框架。
标签: apache perl apache2 cgi fastcgi