我試圖使用fastcgi_module
在Apache2(Apache/2.4.6(Ubuntu))中運行cgi腳本。這是虛擬主機我成立使用fastcgi_module在Apache下永遠運行的CGI腳本(Perl)
<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](http://perldancer.org/)和[Mojolicious](http://mojolicious.org/) – dolmen
@dolmen:錯誤的二分法。 CGI和FastCGI是接口,而不是框架。 – duskwuff