FastCGI和lighttpd使用心得
White paper: FastCGI: A High-Performance Web Server Interface (http://www.fastcgi.com/drupal/node/6?q=node/15)
如果FastCGI在編譯的時候, 發生了EOF Error未定義的問題. 只要在fcgio.cpp的檔案補上#include <cstdio.h>即可解決.
我使用範例裡面的echo.fcgi, 配合lighttpd, 設定如下
###################################################
##
## FastCGI Module
## ---------------
##
## http://www.lighttpd.net/documentation/fastcgi.html
##
server.modules += ( "mod_fastcgi" )
fastcgi.server = ( "/echo.fcgi" => (
"main" => (
# Use host / port instead of socket for TCP fastcgi
# "host" => "127.0.0.1",
# "port" => 3033,
"socket" => "/tmp/echo.sock",
"check-local" => "disable",
"bin-path" => "/tmp/htdocs/echo.fcgi",
"bin-environment" => ("LD_LIBRARY_PATH" => "/home/personlin/lib"), # define the env. vairable for this cgi
"max-procs" => 1,
)
),
)
從設定檔案出,每隻fastcgi都需要有一個socket界接.所以在很多CGI的時候就會有點麻煩.
在啟動lighttpd的時候我用下列的命令
sudo killall lighttpd ; sudo ./sbin/lighttpd -f config/lighttpd.conf -m lib
其中-m的參數,是因為我的lighttpd library並沒有放到標準 /usr/local/lib下面,是在自己家目錄驗證功能.所以執行的時沒有指定-m, ldopen會出現錯誤.
驗證部份,在連到 http://192.168.26.1:8888/echo.fcgi之後,順利的應該會看到環境參數.
Request number 6, Process ID: 26455
如果Request number沒有累加,或者Process ID一直改變,都可能設定上有問題.很可能跑在一般CGI的模式.
#####################################################
##
## CGI modules
## ---------------
##
## http://www.lighttpd.net/documentation/cgi.html
##
server.modules += ( "mod_cgi" )
##
## Plain old CGI handling
##
## For PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini.
##
cgi.assign = ( ".pl" => "/usr/bin/perl",
".cgi" => "/bin/sh",
".rb" => "/usr/bin/ruby",
".erb" => "/usr/bin/eruby",
".py" => "/usr/bin/python" )