搭建Lighttpd

环境:CentOS 5.6 

[root@localhost ~]# uname -a

Linux localhost.localdomain 2.6.18-164.el5 #1 SMP Thu Sep 3 03:33:56 EDT 2009 i686 i686 i386 GNU/Linux

[root@localhost srv]# yum install -y bzip2 bzip2-devel pcre pcre-devel zlib zlib-devel

[root@localhost srv]# tar -zxvf lighttpd-1.4.30.tar.gz

[root@localhost srv]# cd lighttpd-1.4.30

[root@localhost lighttpd-1.4.30]# ./configure --prefix=/usr/local/lighttpd

[root@localhost lighttpd-1.4.30]# make && make install

[root@localhost lighttpd-1.4.30]# groupadd lighttpd

[root@localhost lighttpd-1.4.30]# useradd -g lighttpd lighttpd

[root@localhost lighttpd-1.4.30]# cp doc/initscripts/sysconfig.lighttpd /etc/sysconfig/lighttpd

[root@localhost lighttpd-1.4.30]# mkdir /etc/lighttpd

[root@localhost lighttpd-1.4.30]# cp -rf doc/config/* /etc/lighttpd/

[root@localhost lighttpd-1.4.30]# cp doc/initscripts/rc.lighttpd.redhat /etc/init.d/lighttpd(lighttpd是lighttpd服务启动的脚本)

[root@localhost lighttpd-1.4.30]# vim /etc/init.d/lighttpd

修改

lighttpd="/usr/local/lighttpd/sbin/lighttpd"

[root@localhost lighttpd]# mkdir -p /var/log/lighttpd

[root@localhost lighttpd]# touch /var/log/lighttpd/error.log

[root@localhost lighttpd]# chmod 777 /var/log/lighttpd/error.log 

[root@localhost lighttpd]# mkdir -p /var/www/htdocs

[root@localhost lighttpd]# vim /etc/lighttpd/lighttpd.conf 

修改,注意与第16-20行的路径

server.document-root        = "/var/www/htdocs/"

server.pid-file             = "/var/run/lighttpd.pid"

server.errorlog             = "/var/log/lighttpd/error.log"

[root@localhost lighttpd]# chkconfig --add lighttpd

[root@localhost lighttpd]# chkconfig lighttpd on

[root@localhost lighttpd]# service lighttpd restart

停止 lighttpd:                                            [确定]

启动 lighttpd:                                            [确定]

测试成功:

http://ip/

Lighttpd虚拟主机设置:
[root@localhost lighttpd]# vim /etc/lighttpd/lighttpd.conf 
基于端口的虚拟主机
$SERVER["socket"]=="192.168.159.10:8000"{
server.document-root = "/var/www/htdocs/123/"
server.errorlog = "/var/log/lighttpd/123.log"
accesslog.filename ="/var/log/lighttpd/123-access.log"
}
基于主机头的虚拟主机
$HTTP["host"] == "www.123.com" {
server.document-root = "/var/www/htdocs/123/"
server.errorlog = "/var/log/lighttpd/123.log"
accesslog.filename ="/var/log/lighttpd/123-access.log"
}


网站的访问控制:
仅禁止192.168.1.0这个网段不可以访问,其他可以
$HTTP["remoteip"] == "192.168.1.0/24" {                  
       url.access-deny = ( "" )
 }
 仅允许192.168.1.0这个网段访问,拒绝其他
 $HTTP["remoteip"] != "192.168.1.0/24" {                  
       url.access-deny = ( "" )
 }

禁止192.168.1.0和192.168.2.0网段的访问,其他可以访问 
  $HTTP["remoteip"] =~ "192.168.1.0/24|192.168.2.0/24" {   
       url.access-deny = ( "" )
 }
 允许192.168.1.0和192.168.2.0网段访问,拒绝其他
 $HTTP["remoteip"] !~ "192.168.1.0/24|192.168.2.0/24" {   
       url.access-deny = ( "" )
 }
 
 禁止192.168.1.0网段访问网站的admin这个目录
 $HTTP["remoteip"] != "192.168.1.0/24" {                  
    $HTTP["url"] =~ "^/admin/" {
      url.access-deny = ( "" )
    }
 }

 

你可能感兴趣的:(职场,lighttpd,休闲,darren,darrenpan)