在CentOS5.2的VPS安装lighttpd
弄完查看有关“Nginx”的文章">Nginx又想玩玩lighttpd。lighttpd作为一款和nginx其名的轻量级web服务器,在nginx出名之前也广受大家的喜爱,而且功能也十分的强大。
一、lighttpd简介
官方主页:www.lighttpd.net
Lighttpd是一个德国人领导的开源软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的web server环境。具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。
lighttpd是众多OpenSource轻量级的web server中较为优秀的一个。支持FastCGI, CGI, Auth, 输出压缩 (output compress), URL重写, Alias等重要功能,而Apache之所以流行,很大程度也是因为功能丰富,在lighttpd 上很多功能都有相应的实现了,这点对于apache的用户是非常重要的,因为迁移到lighttpd就必须面对这些问题。
实用起来lighttpd确实非常不错,上文提到的apache overload的问题,用lighttpd就完全解决了。apache主要的问题是密 集并发下,不断的fork()和切换,以及较高(相对于lighttpd而言)的内存占用,使系统的资源几尽枯竭。而lighttpd采用了 Multiplex技术,代码经过优化,体积非常小,资源占用很低,而且反应速度相当快。
利用apache的rewrite技术,将繁重的cgi/fastcgi任务交给lighttpd来完成,充分利用两者的优点,现在那台服务器的负载下降了一个数量级,而且反应速度也提高了一个甚至是2个数量级!
下面是他们官方站点上的一段话:
"lightTPD is the BEST webserver out there, much faster than apache and much much much more flexible/configurable/secure than tux, and its fcgi php support is simply unbeatable."
从这里看出,lighttpd是APACHE的良好替补,功能同样丰富,但是资源消耗更少,并发能力更强。
二、在centos5.2上安装lighttpd
到http://www.lighttpd.net/download下载最新的.tar.gz安装包。
#wget http://www.lighttpd.net/download/lighttpd-1.4.23.tar.gz
#tar -zxf lighttpd-1.4.23.tar.gz
#cd lighttpd-1.4.23
#configure --prefix=/usr/local/lighttpd
我安装的时候报错了,少一个需要的包,我就用yum安装了这个包
# yum -y install pcre-devel
安装后,再configure,成功了
#make
#make install
三、Copy conf文件及启动脚本
#cp doc/lighttpd.conf /usr/local/lighttpd
#cp doc/rc.lighttpd.redhat /etc/init.d/lighttpd
四、 编辑lighttpd启动脚本
#vi /etc/init.d/lighttpd
1,$s#/etc/lighttpd/lighttpd.conf#/usr/local/lighttpd/lighttpd.conf ;全局修改配置文件位置
1,$s#/usr/sbin/lighttpd#/usr/local/sbin/lighttpd ;全局修改lighttpd启动文件
#chkconfig lighttpd on ;添加为服务
五、配置lighttpd.conf
server.document-root = "/var/www/htdocs/" ;server.document-root是服务目录
server.errorlog = "/var/log/lighttpd/error.log" ;server.errorlog是错误日志目录
六、运行
#/etc/init.d/lighttpd start
