Home > i.t. > HOWTO:安装和配置 lighttpd webserver

HOWTO:安装和配置 lighttpd webserver

August 16th, 2008

lighttpd是一个可运行在UNIX/Linux和Windows操作系统上的web服务器软件。和Apache类似。lighttped有时也被称为lighty。

lighttpd特别针对速度进行优化,致力于设计一个安全、快速、与标准兼容和灵活的web服务器。它的小内存占用(和其他web服务器相比)、低cpu负载和快速相应使它更适用于面临负载危机的服务器。请移步官方网站获取详细信息。

本文将指导你如何安装lighttpd服务器,并进行简单配置.

安装lighttpd

如果你使用基于RPM的发行版 (RedHat, Fedora 等) 请从此处下载

下载Fedora Core RPM Binary:
$ cd /tmp
$ wget http://lighttpd.net/download/lighttpd-1.4.13-1.i386.rpm
$ su -
# rpm -ivh lighttpd-1.4.13-1.i386.rpm 

请跳至 配置lighttpd 章节.

Debian Linux 用户使用apt-get命令来安装:
  # apt-get install lighttpd 

请跳至 配置lighttpd 章节.

从源码安装

以上的RPM包不包含mod_rewrite等其他东西,所以你可以从源代码进行编译(注意:源代码安装仅推荐有经验的用户使用):

 $ cd /tmp

取得最新源码:

 $ wget http://lighttpd.net/download/lighttpd-1.4.13.tar.gz 

解压:

$ tar -zxvf lighttpd-1.4.13.tar.gz
$ cd lighttpd-1.4.13
运行 ./configure
$ ./configure --host=i686-redhat-linux-gnu \
         --build=i686-redhat-linux-gnu \
         --target=i386-redhat-linux \
         --program-prefix= --prefix=/usr \
         --exec-prefix=/usr \
         --bindir=/usr/bin \
         --sbindir=/usr/sbin \
         --sysconfdir=/etc \
         --datadir=/usr/share \
         --includedir=/usr/include \
         --libdir=/usr/lib \
         --libexecdir=/usr/libexec \
         --localstatedir=/var \
         --sharedstatedir=/usr/com \
         --mandir=/usr/share/man \
         --infodir=/usr/share/info \
         --with-openssl \
         --with-pcre \
         --with-zlib \
         --with-bzip2 \
         --disable-ipv6 \
         --with-PACKAGE=mod_redirect \
         --with-rewrite \
         --with-redirect \
         --with-ssi

以上编译选项使lighttpd支持SSL, mod_rewrite, ssi, mod_redirect etc. 运行一下命令可以得到具体的参数帮助:

 $ ./configure --help | less

安装lighttpd:

$ make
# make install

创建配置目录:

   # mkdir /etc/lighttpd/ 

创建lighttp用户和用户组

 # groupadd lighttpd
# useradd -g lighttpd -d /var/www/html -s /sbin/nologin lighttpd
OR
# adduser -g lighttpd -d /var/www/html -s /sbin/nologin lighttpd

创建log目录:

   # mkdir /var/log/lighttpd
# chown lighttpd:lighttpd /var/log/lighttpd

下载配置文件和启动文件的sample:

# cd /etc/lighttpd
# wget http://www.cyberciti.biz/tips/wp-content/uploads/2006/07/lighttpd.conf.txt
# mv lighttpd.conf.txt lighttpd.conf
# chown lighttpd:root /etc/lighttpd/lighttpd.conf
# cd /etc/init.d/
# wget http://www.cyberciti.biz/tips/wp-content/uploads/2006/07/lighttpd.txt
# mv lighttpd.txt lighttpd
# chmod +x lighttpd 

配置lighttpd

下面两个文件对lighttpd很重要:

  • 默认的lighttpd配置文件: /etc/lighttpd/lighttpd.conf
  • lighttpd服务启动脚本: /etc/init.d/lighttpd

所有的二进制方式安装都会安装这两个文件。
现在lighttpd已安装完成。下面开始配置。

删除apache

如果你不准备再使用Apache v1.3/2.x ,最好删除它 (确保你备份了数据文件和配置文件):

# rpm -e httpd
# yum remove httpd
# apt-get remove apache2
理解lighttpd主要配置参数

下面是lighttpd的主要配置参数:

  • server.document-root = “/var/www/html”: 指定服务器的默认根目录。
  • server.port = 80: 指定默认的http端口。
  • server.username = “lighttpd”
  • server.groupname = “lighttpd”: 指定开启和停止lighttpd服务的默认用户和用户组。这是一个安全功能(可以不必是root来操作)。
  • server.bind = “server-ip-address”: 指定服务器IP或域名,如 theos.in.
  • server.tag =”lighttpd”: 用来设置lighttpd的名称和版本(默认)。 这也是一个安全功能。 你可以设置成如下值:
    server.tag ="myWebServer v1.0"

    注意,这个信息会在http头中显示。 (可以通过 netcraft看到)

  • server.errorlog = “/var/log/lighttpd/error.log”: 指定错误日志文件。
  • accesslog.filename = “/var/log/lighttpd”: 指定访问日志文件(可通过日志文件分析得到访问统计信息)。
  • index-file.names = ( “index.php”, “index.html” ): 指定index文件.

server.modules = (
“mod_access”,
“mod_accesslog”,
“mod_fastcgi”,
“mod_rewrite”,
“mod_auth”
)
: 以上模块会被加载:

  • mod_access: 用来限制访问某些后缀的文件
  • mod_accesslog: 记录CLF log, 类似与apache
  • mod_fastcgi : FastCGI调用perl/PHP等
  • mod_rewrite : 生成SEO友好的url
  • mod_auth: 验证(用密码保护目录)

mimetype.assign = (
“.pdf” => “application/pdf”,
“.sig” => “application/pgp-signature”
)
: 设置mimetype映射.

打开文件/etc/lighttpd/lighttpd.conf,设置以上参数:


# vi /etc/lighttpd/lighttpd.conf

保存文件,启动lighttpd:


# /etc/init.d/lighttpd start

验证lighttpd是否在运行:


$ netstat -ntulp

Output:

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      29855/sshd
tcp        0      0 203.111.103.81:80           0.0.0.0:*                   LISTEN      5866/lighttpd
...
.....
..

打开浏览器,输入url测试: http://your-domain.com/ or http://server-ip/

webflier i.t.

  1. No comments yet.
  1. No trackbacks yet.