`
tl_oni
  • 浏览: 29653 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

安装lighttpd

阅读更多

 

1.         安装编译环境

  LINUX5.5 光盘中 server 目录下找到如下 rpm 包:

升级安装

rpm -Uvh --force --nodeps *rpm

 

2.         下载 lighttpd

http://lighttpd.net/download/下载最新的源码 lighttpd-1.4.28.tar.gz

$ gzip -cd lighttpd-1.4.28.tar.gz | tar xf 

$ cd lighttpd-1.4.28

$./configure --host=i386-linux   --prefix=/usr/local/lighttpd-1.4.28-linux

////////////--build=arm-linux --target=arm-linux

$make

$make install

 

复制lighttpd.confmodules.conf

到指定目录

$  



mkdir /usr/local/lighttpd/etc

$ cp doc/config/lighttpd.conf usr/local/lighttpd-1.4.28-linux/etc/ 

$ cp  

doc/config/

modules

.conf  

/usr/local/lighttpd-1.4.28-linux/etc 

 

#

权限配置  

groupadd lighttpd
useradd     lighttpd lighttpd
mkdir /www
chown -R lighttpd.lighttpd /www
mkdir /home/lighttpd/logs
chown -R lighttpd.lighttpd /home/lighttpd/logs
chmod 750 /lighttpd/logs

# 安装文件下的启动脚本
cp doc/initscripts/rc.lighttpd /etc/init.d/lighttpd
chkconfig lighttpd on

修改 /etc/init.d/lighttpd ,将配置文件变量更改为:
vi /etc/init.d/lighttpd
# LIGHTTPD_CONFIG=/etc/sysconfig/lighttpd
  LIGHTTPD_CONFIG=/usr/local/lighttpd-1.4.28-linux/etc/lighttpd.conf

LIGHTTPD_BIN =/usr/local/lighttpd-1.4.28-linux/sbin/lighttpd

LIGHTTPD_CONF_PATH=/usr/local/lighttpd-1.4.28-linux/etc/lighttpd.conf

3.         配置

$vi /usr/local/lighttpd-1.4.28-linux/etc/ lighttpd.conf

1)        server.port = 80 改成 server.port = 8899 ,后面的端口只要不重复就可以了;

2)        server.use-ipv6 = “enable” 此行注释掉 # server.use-ipv6 = “enable”

3)        建立相关目录

  var.log_root    = "/home/lighttpd/logs "

var.server_root = "/www"

var.state_dir   = "/home/lighttpd/run"

var.home_dir    = "/home/lighttpd/lib/lighttpd"

var.conf_dir    = "/home/lighttpd/lighttpd"

4.         启动 lighttpd

$ cd /usr/local/lighttpd-1.4.28-linux

$ ./sbin/lighttpd -f ./etc/lighttpd.conf

5.         测试

编辑 index.html 文件

vi /www /htdocs/index.html

hello world

 

在浏览器地址输入 http://ip:8899/index.html

显示出页面信息

6.         其它

一,为什么要使用 lighttpd?
apache
不可以吗?
在支持纯静态的对象时,比如图片,文件等
lighttpd
速度更快,更理想
至于它和 apache 的比较,很多文档,大家可以 google 一下
二,从何处下载 lighttpd?
http://www.lighttpd.net/download/
这个是它的官方站
三,如何安装?
1,
编译安装
./configure --prefix=/usr/local/lighttpd
make
make install
configure
完毕以后,会给出一个激活的模块和没有激活模块的清单,可以检查一下,是否自己需要的模块都已经激活,在 enable 的模块中一定要有 “mod_rewrite” 这一项,否则重新检查 pcre 是否安装。
2,
编译后配置
cp doc/sysconfig.lighttpd /etc/sysconfig/lighttpd
mkdir /etc/lighttpd
cp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf
如果你的 Linux RedHat/CentOS ,那么:
cp doc/rc.lighttpd.redhat /etc/init.d/lighttpd
如果你的 Linux SuSE ,那么:
cp doc/rc.lighttpd /etc/init.d/lighttpd
其他 Linux 发行版本可以自行参考该文件内容进行修改。
然后修改 /etc/init.d/lighttpd ,把
LIGHTTPD_BIN=/usr/sbin/lighttpd
改为
LIGHTTPD_BIN=/usr/local/lighttpd/sbin/lighttpd
此脚本用来控制 lighttpd 的启动关闭和重起:
/etc/init.d/lighttpd start
/etc/init.d/lighttpd stop
/etc/init.d/lighttpd restart
3,
配置
修改 /etc/lighttpd/lighttpd.conf
1
server.modules
取消需要用到模块的注释, mod_rewrite mod_access mod_fastcgi mod_simple_vhost mod_cgi mod_compress mod_accesslog 是一般需要用到的。
我们放开 "mod_rewrite"
"mod_compress",
2
server.document-root, server.error-log accesslog.filename 需要指定相应的目录
server.document-root = "/www/phc/html/"
mkdir /usr/local/lighttpd/logs
chmod 777 /usr/local/lighttpd/logs/
touch /usr/local/lighttpd/logs/error.log
chmod 777 /usr/local/lighttpd/logs/error.log
server.errorlog = "/usr/local/lighttpd/logs/error.log"
accesslog.filename = "|/usr/sbin/cronolog /usr/local/lighttpd/logs/%Y/%m/%d/accesslog.log"
3
)用什么权限来运行 lighttpd
server.username = "nobody"
server.groupname = "nobody"
从安全角度来说,不建议用 root 权限运行 web server ,可以自行指定普通用户权限。
4
)静态文件压缩
mkdir /usr/local/lighttpd/compress
chmod 777 /usr/local/lighttpd/compress/
compress.cache-dir = "/usr/local/lighttpd/compress/"
compress.filetype = ("text/plain", "text/html","text/javascript","text/css")
可以指定某些静态资源类型使用压缩方式传输,节省带宽,
对于大量 AJAX 应用来说,可以极大提高页面加载速度。
5
server.port = 81
6
#$HTTP["url"] =~ "\.pdf$" {
131 # server.range-requests = "disable"
132 #}

4 ,优化
1
最大连接数
默认是 1024
修改 server.max-fds, 大流量网站推荐 2048.
因为 lighttpd 基于线程 , apache(MPM-prefork) 基于子进程 ,
所以 apache 需要设置 startservers,maxclients , 这里不需要
2 stat()
缓存
stat()
这样的系统调用 , 开销也是相当明显的 .
缓存能够节约时间和环境切换次数 (context switches)
一句话 ,lighttpd.conf 加上
server.stat-cache-engine = “fam”
lighttpd
还另外提供 simple( 缓存 1 秒内的 stat()),disabled 选项 .
相信没人会选 disabled .
3
常连接 (HTTP Keep-Alive)
一般来说 , 一个系统能够打开的文件个数是有限制的 ( 文件描述符限制 )
常连接占用文件描述符 , 对非并发的访问没有什么意义 .
(
文件描述符的数量和许多原因有关 , 比如日志文件数量 , 并发数目等 )
这是 lighttpd keep-alive 方面的默认值 .
server.max-keep-alive-requests = 128
server.max-keep-alive-idle = 30
换言之 ,lighttpd 最多可以同时承受 30 秒长的常连接 , 每个连接最多请求 128 个文件 .
但这个默认值确实不适合非并发这种多数情况 .
lighttpd.conf
中减小
server.max-keep-alive-requests
server.max-keep-alive-idle
两个值 , 可以减缓这种现象 .
甚至可以关闭 lighttpd keep-alive.
server.max-keep-alive-requests = 0
4
事件处理
对于 linux kernel 2.6 来说 , 没有别的可说
lighttpd.conf
中加上这一句足矣
server.event-handler = “linux-sysepoll”
另外 ,
linux 2.4
使用 linux-rtsig
freebsd
使用 freebsd-kqueue
unix
使用 poll
5
网络处理
lighttpd
大量使用了 sendfile() 这样一个高效的系统调用 .
减少了从应用程序到网卡间的距离 .
(
同时也减少了 lighttpd cpu 的占用 , 这部分占用转嫁到内核身上了 )
根据平台 , 可以设置不同的参数 .
server.network-backend = “linux-sendfile”
(linux)
freebsd: freebsd-sendfile
unix: writev
如果有兴趣的话 , 也可以看看 lighttpd async io(aio) 上的实现 , 仅限 lighttpd 1.5
(linux-aio-sendfile, posix-aio, gthread-aio)
此外 , 网络方面 , 核心的参数也需要适当进行修改 ,
这里就不需要详细说明了 .

5,
启动
6,
配置日志
logrotate & cronolog
logrotate
很粗暴 , 直接把进程砍了然后移动日志
cronolog
就是比较不错的方式 .
lighttpd
用法 :
accesslog.filename = " |/usr/sbin/cronolog /var/log/lighttpd/%Y/%m/%d/access_XXXX.log"

7,
安装 pcre
从何处下载 ?
http://www.pcre.org/
wget ftp://ftp.csx.cam.ac.uk/pub/soft ... re/pcre-7.4.tar.bz2
安装过程:
./configure
make clean
make
make install
8,
支持 fam
gamin
默认已安装了此包
yum install gamin-devel
另外配置时需添加:
./configure --prefix=/usr/local/lighttpd --with-fam
9,
测试 lighttpd 的启动:
/usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics