Lighttpd的安装与配置

Eave 2015.09.10 18:43

lighttpd,是一个德国人领导的开源软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好。lighttpd并且灵活的web server环境。具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。lighttpd是众多OpenSource轻量级的web server中较为优秀的一个。支持FastCGI, CGI, Auth, 输出压缩(output compress), URL重写, Alias等重要功能。

一、下载pcre库

下载地址:

http://www.linuxfromscratch.org/blfs/view/svn/general/pcre.html
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.bz2

二、编译安装pcre库

$ tar -jxf  pcre-8.37.tar.bz2
$ cd pcre-8.37
$ ./configure
$ make
$ make install

三、下载lighttpd

下载地址:

http://www.lighttpd.net/download
$ wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.37.tar.gz

四、编译安装lighttpd

$ tar -xzf lighttpd-1.4.37.tar.gz
$ cd lighttpd-1.4.37
$ ./configure --prefix=/usr/local/lighttpd
$ make
$ make install

五、 编译后配置

$ useradd lighttpd
$ mkdir -p /var/log/lighttpd
$ chown lighttpd:lighttpd /var/log/lighttpd
$ mkdir -p /var/cache/lighttpd
$ chown lighttpd:lighttpd /var/cache/lighttpd
$ mkdir -p /var/www/lighttpd
$ chown lighttpd:lighttpd /var/www/lighttpd
$ echo "Welcome to Lighttpd" > /var/www/lighttpd/index.html

$ cp -a doc/config/modules.conf /usr/local/lighttpd/
$ cp -a doc/config/lighttpd.conf /usr/local/lighttpd/
$ cp -a doc/config/conf.d /usr/local/lighttpd/
$ cp -a doc/config/vhosts.d /usr/local/lighttpd/
$ cp -a doc/initscripts/rc.lighttpd.redhat /etc/init.d/lighttpd
$ cp -a doc/initscripts/sysconfig.lighttpd /etc/sysconfig/lighttpd

如果你的Linux不是RedHat或CentOS,那么

$ cp doc/initscripts/rc.lighttpd /etc/init.d/lighttpd

修改/etc/init.d/lighttpd

if [ -z "$LIGHTTPD_CONF_PATH" ]; then
    LIGHTTPD_CONF_PATH="/etc/sysconfig/lighttpd.conf"
fi
改为
#if [ -z "$LIGHTTPD_CONF_PATH" ]; then
    LIGHTTPD_CONF_PATH="/usr/local/lighttpd/lighttpd.conf"
#fi

lighttpd="/usr/sbin/lighttpd"

改为

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

vim /usr/local/lighttpd/lighttpd.conf
var.log_root    = "/var/log/lighttpd"
var.server_root = "/srv/www"
var.state_dir   = "/var/run"
var.home_dir    = "/var/lib/lighttpd"
var.conf_dir    = "/etc/lighttpd"

改为

var.log_root    = "/var/log/lighttpd"
var.server_root = "/var/www"
var.state_dir   = "/var/run"
var.home_dir    = "/var/lib/lighttpd"
var.conf_dir    = "/usr/local/lighttpd"

server.use-ipv6 = "enable"

改为

server.use-ipv6 = "disable"

server.document-root = server_root + "/htdocs"

改为

server.document-root = server_root + "/lighttpd"

六、配置开机启动Lighttpd

$ chkconfig --add lighttpd
$ chkconfig lighttpd on

七、启动Lighttpd

$ /etc/init.d/lighttpd start

访问http://192.168.1.7,出现"Welcome to Lighttpd"字样这表明Lighttpd启动成功.