Lighttpd 安装与配置初步

Lighttpd是一个德国人领导的开源软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的web server环境。具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。lighttpd是众多OpenSource轻量级的web server中较为优秀的一个。支持FastCGI, CGI, Auth, 输出压缩(output compress), URL重写, Alias等重要功能,而Apache之所以流行,很大程度也是因为功能丰富,在lighttpd上很多功能都有相应的实现了,这点对于apache的用 户是非常重要的,因为迁移到lighttpd就必须面对这些问题。下面先简要的介绍下lighttpd的安装和基本配置,基于RedHat enterprise Linux 5.4

[root@server1 ~]# cd /usr/local/src/tarbag/
[root@server1 tarbag]# wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.26.tar.gz
[root@server1 tarbag]# tar -zxvf lighttpd-1.4.26.tar.gz -C ../software/
[root@server1 tarbag]# cd ../software/lighttpd-1.4.26/
[root@server1 lighttpd-1.4.26]# ./configure --prefix=/usr/local/lighttpd --with-openssl --with-pcre --with-memcache --with-zlib --with-bzip2 --with-mysql --with-ldap
//详细的编译选项,可以使用./configure --help进行查看
Plugins:

enabled:
mod_access
mod_accesslog
mod_alias
mod_auth
mod_cgi
…… ……
disabled:
mod_cml
mod_magnet

Features:

enabled:
auth-crypt
auth-ldap
compress-bzip2
compress-deflate
compress-gzip
…… ……
disabled:
stat-cache-fam
storage-gdbm
storage-memcache
…… ……

[root@server1 lighttpd-1.4.26]# make && make install

[root@server1 lighttpd-1.4.26]# ls /usr/local/lighttpd/
lib sbin share
[root@server1 lighttpd-1.4.26]# mkdir /usr/local/lighttpd/etc   /usr/local/lighttpd/run
[root@server1 lighttpd-1.4.26]# cp doc/lighttpd.conf     /usr/local/lighttpd/etc             //从doc目录中复制主配置文件
[root@server1 lighttpd-1.4.26]# cp doc/sysconfig.lighttpd   /etc/sysconfig/lighttpd          //从doc目录中复制先锋配置文件
[root@server1 lighttpd-1.4.26]# cat /etc/sysconfig/lighttpd              //该文件定义了主配置文件的位置,供service脚本调用
LIGHTTPD_CONF_PATH=/usr/local/lighttpd/etc/lighttpd.conf

[root@server1 lighttpd-1.4.26]# grep -v '^#' /usr/local/lighttpd/etc/lighttpd.conf |uniq

server.modules              = (                   //以下为加载的模块
                               "mod_rewrite",
                               "mod_redirect",
                               "mod_alias",
                               "mod_access",
                               "mod_auth",
                               "mod_status",
                               "mod_setenv",
                               "mod_fastcgi",
                               "mod_proxy",
                               "mod_simple_vhost",
                               "mod_evhost",
                               "mod_userdir",
                               "mod_cgi",
                               "mod_compress",
                               "mod_ssi",
                               "mod_usertrack",
                               "mod_expire",
                               "mod_secdownload",
                               "mod_accesslog" )

server.document-root        = "/www/htdocs/"        //默认以IP访问读取的网站根目录

server.errorlog             = "/www/log/lighttpd/error.log" //错误日志文件位置

index-file.names            = ( "index.php", "index.html",   //首页文件的名称
                                "index.htm", "default.htm" )

mimetype.assign             = (
".pdf"          =>      "application/pdf",
".sig"          =>      "application/pgp-signature",

……………………输出省略…………………………………
""              =>      "application/octet-stream",
)

server.tag                 = "lighttpd"

accesslog.filename          = "/www/log/lighttpd/access.log" //访问日志文件位置

url.access-deny             = ( "~", ".inc" ) //拒绝访问的文件类型

$HTTP["url"] =~ "/.pdf$" {
server.range-requests = "disable"
}

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

server.port                = 80        //侦听80端口

server.bind                = "0.0.0.0" //在本机所以IP地址上侦听

server.pid-file            = "/usr/local/lighttpd/run/lighttpd.pid" //PID文件位置

$HTTP["host"] == "web1.yang.com" {     //虚拟主机设定
server.name = "web1.yang.com"
server.document-root = "/www/vhosts/web1"
server.errorlog = "/www/log/lighttpd/web1.yang.com-error.log"
accesslog.filename = "/www/log/lighttpd/web1.yang.com-access.log"
}

$HTTP["host"] == "web2.yang.com" {
server.name = "web2.yang.com"
server.document-root = "/www/vhosts/web2"
server.errorlog = "/www/log/lighttpd/web2.yang.com-error.log"
accesslog.filename = "/www/log/lighttpd/web2.yang.com-access.log"
}

server.chroot              = "/"        //使用chroot

server.username            = "daemon"   //以daemon用户和组来启动lighttpd

server.groupname           = "daemon"

status.status-url          = "/server-status" //启用status和config页面信息查看
status.config-url          = "/server-config

配置service脚本:
[root@server1 lighttpd-1.4.26]# cp doc/rc.lighttpd.redhat   /etc/init.d/lighttpd
[root@server1 lighttpd-1.4.26]# chmod +x /etc/init.d/lighttpd
[root@server1 lighttpd-1.4.26]# chkconfig --add lighttpd
[root@server1 lighttpd-1.4.26]# chkconfig lighttpd on
[root@server1 lighttpd-1.4.26]# grep -E 'sbin|lighttpd.conf' /etc/init.d/lighttpd |grep -v '^#'   //修改脚本中的相关信息如下
        LIGHTTPD_CONF_PATH="/usr/local/lighttpd/etc/lighttpd.conf"
lighttpd="/usr/local/lighttpd/sbin/lighttpd"

[root@server1 lighttpd-1.4.26]# service lighttpd start
启动 lighttpd:[确定]

[root@server1 lighttpd-1.4.26]# ps -ef |grep lighttpd |grep -v 'grep'
daemon    3378     1 0 14:31 ?        00:00:00 /usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf

[root@server1 lighttpd-1.4.26]# netstat -ntpl |grep :80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      3378/lighttpd  

[root@server1 lighttpd-1.4.26]# tail -f /www/log/lighttpd/web1.yang.com-access.log //查看访问日志
192.168.122.10 web1.yang.com - [13/Jun/2010:14:08:03 +0800] "GET / HTTP/1.1" 200 17 "-" "Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.0.12) Gecko/2009070811 Red Hat/3.0.12-1.el5_3 Firefox/3.0.12"

[root@server1 lighttpd-1.4.26]# tail -f /www/log/lighttpd/web2.yang.com-access.log
192.168.122.10 web2.yang.com - [13/Jun/2010:14:08:44 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.0.12) Gecko/2009070811 Red Hat/3.0.12-1.el5_3 Firefox/3.0.12"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值