Chinaunix首页 | 论坛 | 博客
  • 博客访问: 100104655
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: LINUX

2008-05-25 13:50:21

 
 
(2) 整合php和fastcgi
以php-4.3.11为例,编译PHP的时候,不能指定 --with-apxs选项,编译命令行大致如下:
$ ./configure ... --enable-force-cgi-redirect --enable-fastcgi
$ make
$ sapi/cgi/php -v
PHP 4.3.11 (cgi-fcgi) (built: Jan 30 2006 00:12:34)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
make完了后,会在sapi/cli目录生成命令行下的php程序,sapi/cgi下生成fastcgi下的php程序。如果执行sapi/cgi下的php显示版本号,你会发现有 cgi-fcgi的说明,这就表明你成功了。
$ mkdir /usr/local/lighttpd-1.4.9/fcgi
$ cp sapi/cgi/php /usr/local/lighttpd-1.4.9/fcgi/
$ vi /usr/local/lighttpd-1.4.9/lighttpd.conf
我们建立一个子目录fcgi用来保存所有的fast-cgi程序,然后把php拷贝到该目录下。编辑lighttpd.conf,如下所示:
...
server.modules = (
...
"mod_fastcgi",
...)
...
fastcgi.server = (".php" =>
( "127.0.0.1" =>
(
"socket" => "/tmp/fcgi_php.sock",
"bin-path" => "/usr/local/lighttpd-1.4.9/fcgi/php"
)
)
)
重新启动lighttpd就可以了。Lighttpd和fastcgi通信有两种方式:通过Unix socket通信,如以上PHP的启动;通过TCP/IP socket通信。Lighttpd支持基于fastcgi的负载均衡,不过我没尝试过。
关于fastcgi的协议规范,请参考,以下是我自己写的一个fastcgi的配置样例:
fastcgi.server = ( "/fastcgi/adsim" =>
( "127.0.0.1" =>
(
"host" => "127.0.0.1",
"port" => 4000,
"bin-path" => "/usr/local/lighttpd-1.4.9/fcgi/adsim",
"check-local" => "disable"
)
)
check-local必须设置为disable,否则因为找不到/fastcgi/adsim会导致请求失败。
(3) 制作lighttpd启动脚本
每次启动lighttpd时我们要指定配置文件的位置,停止lighttpd时要先找到进程号,然后用kill发送停止信号,有点太麻烦了。好在lighttpd自带了一个脚本程序能辅助完成这些操作,只要稍微改改就能用了,那就是源码目录doc/rc.lighttpd和doc/rc.lighttpd.redhat,后者专用于RedHat Linux。主要的改动之处在于:
...
if [ -z "$LIGHTTPD_CONF_PATH" ]; then
LIGHTTPD_CONF_PATH="/usr/local/lighttpd-1.4.9/lighttpd.conf"
fi
...
lighttpd="/usr/local/lighttpd-1.4.9/usr/sbin/lighttpd"
...
用这个脚本管理lighttpd是不是方便多了。
(4) Lighttpd和OpenSSL
Lighttpd默认不编译ssl模块,所以必须在编译的时候明确指定 --with-openssl,然后再生成自签署的服务器证书或者从CA那里获取。生成自签署证书的方法如下:
$ openssl req -new -x509 -keyout server.pem \
-out server.pem -days 365 -nodes
Lighttpd要求证书和私匙保存在同一个文件里,如果是分开的,则需要合并:
$ cat host.key host.crt > host.pem
配置lighttpd.conf,大致样子如下:
ssl.engine = "enable"
ssl.pemfile = "server.pem"
你可以针对某个虚拟主机做这样的设置,但是由于SSL工作在TCP层,所以不能设置基于名称的虚拟主机,只能设置基于端口的。 以下是一个配置样例:
$SERVER["socket"] == "192.168.146.128:443" {
ssl.engine = "enable"
ssl.pemfile = "/usr/local/lighttpd/certs/server.pem"
server.document-root = "/home/www/wfs/www"
}
 
来自: 新客网() 详文参考:
阅读(325) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~