noo*_*ana 2 apache perl cgi fastcgi apache2
我正在尝试使用Apache2(Apache/2.4.6(Ubuntu))运行cgi脚本fastcgi_module.这是我设置的虚拟主机
<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>
Run Code Online (Sandbox Code Playgroud)
这是我创建的用于运行测试()的Perl脚本(正确775'/home/noobeana/CGI/test.pl):
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello there!<br />\n";
Run Code Online (Sandbox Code Playgroud)
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'
Run Code Online (Sandbox Code Playgroud)
我不确定这两个问题(print浏览器中没有输出和脚本没有终止)是否相关.
你想要做的是不可能的.fastcgi_module只能运行实现FastCGI接口的脚本,而您编写的脚本不支持该脚本.相反,fastcgi_module它反复尝试启动你的"FastCGI"脚本,看到它打印出一些东西并立即退出 - 哪些FastCGI脚本不应该这样做 - 并且摸不着头脑,想知道它做错了什么.
一个简单的脚本,确实实现了正确的接口可以使用来实现CGI::Fast模块:
#!/usr/bin/perl
use strict;
use CGI::Fast;
while (my $CGI = CGI::Fast->new) {
print $CGI->header();
print "Hello there\n";
}
Run Code Online (Sandbox Code Playgroud)
(FastCGI协议有点复杂,因此没有使用模块就没有合理的方法来实现它.)
| 归档时间: |
|
| 查看次数: |
352 次 |
| 最近记录: |