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

Lighttpd 的安装配置

阅读更多

lighttpd(http://lighttpd.net/)和apache一样是开源的,与apache相比,虽然功能不及apache完善, 稳定性也不如apache,但是,不管是服务静态页面,还是服务动态内容(CGI,PHP),它都比apache快,用于ad banner之类的WEB服务器是最恰当不过了。

本文从应用的角度,说明如何安装、配置lighttpd。

(1) 安装

可从http://lighttpd.net/download/下载最新的源码(.tar.gz)或者rpm包。如果下载的是.tar.gz文 件,则和GNU的其他软件一样,先./configure一下,然后 make && make install就搞定了。但是如果你想定制一些功能,就得好好看看解压后README, INSTALL以及./configure --help的输出结果了。这里仅仅说一下如何从源码安装,其他安装方式可参考 http://trac.lighttpd.net/trac/wiki/TutorialInstallation。

$ gzip -cd lighttpd-1.4.9.tar.gz | tar xf -
...
$ cd lighttpd-1.4.9
$ ./configure --help
`configure' configures lighttpd 1.4.9 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
...

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
...

Program names:
...

System types:
...

Optional Features:
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-maintainer-mode  enable make rules and dependencies not useful
                          (and sometimes confusing) to the casual installer
  --disable-dependency-tracking  speeds up one-time build
  --enable-dependency-tracking   do not reject slow dependency extractors
  --enable-static[=PKGS]
                          build static libraries [default=no]
  --enable-shared[=PKGS]
                          build shared libraries [default=yes]
  --enable-fast-install[=PKGS]
                          optimize for fast installation [default=yes]
  --disable-libtool-lock  avoid locking (might break parallel builds)
  --enable-lfs            Turn on Large File System (default)
  --disable-ipv6          disable IPv6 support

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
  --with-pic              try to use only PIC/non-PIC objects [default=use
                          both]
  --with-tags[=TAGS]
                          include additional configurations [automatic]
  --with-mysql[=PATH]
                          Include MySQL support. PATH is the path to
                          'mysql_config'
  --with-ldap             enable LDAP support
  --with-attr             enable extended attribute support
  --with-valgrind         enable internal support for valgrind
  --with-openssl[=DIR]
                          Include openssl support (default no)
  --with-openssl-includes=DIR
                          OpenSSL includes
  --with-openssl-libs=DIR OpenSSL libraries
  --with-kerberos5        use Kerberos5 support with OpenSSL
  --with-pcre             Enable pcre support (default yes)
  --with-bzip2            Enable bzip2 support for mod_compress
  --with-fam              fam/gamin for reducing number of stat() calls
  --with-webdav-props     properties in mod_webdav
  --with-gdbm             gdbm storage for mod_trigger_b4_dl
  --with-memcache         memcached storage for mod_trigger_b4_dl
  --with-lua              lua engine for mod_cml

Some influential environment variables:
...

如上所述,可通过--prefix指定安装路径,默认安装在/usr/local下。可以指定启用哪些特征(插件),禁用哪些特征(插件)。假定我们要把lighttpd安装到/usr/local/lighttpd-1.4.9下面。

$ ./configure --prefix=/usr/local/lighttpd-1.4.9
$ make
$ make install
$ cp  doc/lighttpd.conf /usr/local/lighttpd-1.4.9/  # 拷贝配置文件 
$ cd /usr/local/lighttpd-1.4.9
$ vi lighttpd.conf # 修改配置文件

配置文件很直观明了,一般只要把server.document-root、server.errorlog、accesslog.filename改成你的实际目录和文件名字就可以了。

$ sbin/lighttpd -f lighttpd.conf # 启动lighttpd服务
$ ps aux | grep lighttpd
www 15403  0.0  0.9  2860 1148 ? S 00:15 0:00 sbin/lighttpd -f

这就完成了从安装到启动的整个过程,很简单吧。从最后一行的输出可以看出,lighttpd是单进程服务的,这和apache不一样(也许是它的稳定性不如apache的一个原因)。

(2) 整合php和fastcgi

以php-4.3.11为例,编译PHP的时候,不能指定 --with-apxs选项,编译命令行大致如下:

$ ./configure ... --enable-force-cgi-redirect --enable-fastcgi
$ make
$ sapi/cgi/php -v
PHP 4.3.11 (cgi-fcgi) (built: Jan 30 2006 00:12:34)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

make完了后,会在sapi/cli目录生成命令行下的php程序,sapi/cgi下生成fastcgi下的php程序。如果执行sapi/cgi下的php显示版本号,你会发现有 cgi-fcgi的说明,这就表明你成功了。

$ mkdir /usr/local/lighttpd-1.4.9/fcgi
$ cp sapi/cgi/php /usr/local/lighttpd-1.4.9/fcgi/
$ vi /usr/local/lighttpd-1.4.9/lighttpd.conf

我们建立一个子目录fcgi用来保存所有的fast-cgi程序,然后把php拷贝到该目录下。编辑lighttpd.conf,如下所示:

...
server.modules = (
 ...
 "mod_fastcgi",
 ...)
...
fastcgi.server = (".php" =>
 ( "127.0.0.1" =>
  (
   "socket" => "/tmp/fcgi_php.sock",
   "bin-path" => "/usr/local/lighttpd-1.4.9/fcgi/php"
  )
 )
 )

重新启动lighttpd就可以了。Lighttpd和fastcgi通信有两种方式:通过Unix socket通信,如以上PHP的启动;通过TCP/IP socket通信。Lighttpd支持基于fastcgi的负载均衡,不过我没尝试过。

关于fastcgi的协议规范,请参考http://www.fastcgi.com/,以下是我自己写的一个fastcgi的配置样例:

fastcgi.server = ( "/fastcgi/adsim" =>
 ( "127.0.0.1" =>
  (
   "host" => "127.0.0.1",
   "port" => 4000,
   "bin-path" => "/usr/local/lighttpd-1.4.9/fcgi/adsim",
   "check-local" => "disable"
  )
)

check-local必须设置为disable,否则因为找不到/fastcgi/adsim会导致请求失败。

(3) 制作lighttpd启动脚本

每次启动lighttpd时我们要指定配置文件的位置,停止lighttpd时要先找到进程号,然后用kill发送停止信号,有点太麻烦了。好在 lighttpd自带了一个脚本程序能辅助完成这些操作,只要稍微改改就能用了,那就是源码目录doc/rc.lighttpd和doc /rc.lighttpd.redhat,后者专用于RedHat Linux。主要的改动之处在于:

...
if [ -z "$LIGHTTPD_CONF_PATH" ]; then
        LIGHTTPD_CONF_PATH="/usr/local/lighttpd-1.4.9/lighttpd.conf"
fi
...
lighttpd="/usr/local/lighttpd-1.4.9/usr/sbin/lighttpd"
...

用这个脚本管理lighttpd是不是方便多了。

(4) Lighttpd和OpenSSL

Lighttpd默认不编译ssl模块,所以必须在编译的时候明确指定 --with-openssl,然后再生成自签署的服务器证书或者从CA那里获取。生成自签署证书的方法如下:

$ openssl req -new -x509 -keyout server.pem \
 -out server.pem -days 365 -nodes

Lighttpd要求证书和私匙保存在同一个文件里,如果是分开的,则需要合并:

$ cat host.key host.crt > host.pem

配置lighttpd.conf,大致样子如下:

ssl.engine = "enable"
ssl.pemfile = "server.pem"

你可以针对某个虚拟主机做这样的设置,但是由于SSL工作在TCP层,所以不能设置基于名称的虚拟主机,只能设置基于端口的。 以下是一个配置样例:

$SERVER["socket"] == "192.168.146.128:443" {
       ssl.engine = "enable"
       ssl.pemfile = "/usr/local/lighttpd/certs/server.pem"
       server.document-root = "/home/www/wfs/www"
}

(5) 配置目录列表

修改 lighttpd.conf,大致如下所示:

server.module = {
 ...
 "mod_dirlisting",
 ...}

dir-listing.activate = "enable"

(6) 配置CGI

修改lighttpd.conf,首先需要启动mod_cgi,然后在static-file.exclude-extensions中指定cgi文件的扩展名,最后通过cgi.assign配置指令进行关联。

对于带扩展名且需要特定解析程序执行的CGI,可以指定解析程序的路径,比如:

cgi.assign = ( ".pl"  => "/usr/bin/perl",
 ".cgi" => "/usr/bin/perl" )

对于带扩展名切不需要特定解析程序就能执行的CGI,可指定解析程序为空,比如:

cgi.assign = (".cgi" => "")

对于不带扩展名的CGI程序,只能通过固定路径存取了,比如:

cgi.assgin = ( "/cgi-bin/mycgi" => "/usr/local/cgi/mycgi )

(7) 配置虚拟主机

配置基于端口的虚拟主机上文有所描述,基于名称的虚拟主机也很简单。修改lighttpd.conf,启动模块mod_simple_vhost,然后指定你的虚拟主机信息,比如:

$HTTP["host"] == "news.example.org" {
  server.document-root = "/var/www/servers/news2.example.org/pages/"
}

Lighttpd注重于速度,而Apache注重于稳定性和功能,怎么选择还得看具体的应用。

 

2. 解压、安装、配置

shell> tar zxvf lighttpd-1.5.0-r1691.tar.gz
shell> cd lighttpd-1.5.0
shell> ./configure --prefix=/usr/local/lighttpd
shell> ./make
shell> ./make install
shell> cp doc/rc.lighttpd.redhat /etc/rc.d/init.d/lighttpd
shell> chmod 777 /etc/rc.d/init.d/lighttpd
shell> cp doc/sysconfig.lighttpd /etc/sysconfig/lighttpd
shell> mkdir /etc/lighttpd
shell> cp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf
shell> chkconfig lighttpd on

接下来打开/etc/rc.d/init.d/lighttpd修改lighttpd的值如下

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

打开/etc/lighttpd/lighttpd.conf修改服务的端口(默认是80),以及文档根目录的路径(默认是/www/pages)后启动lighttpd服务

shell> service lighttpd start

更多关于lighttpd的配置请看lighttpd的文档
附注

在lighttpd中可以通过下面的配置来实现每天一个访问日志文件

accesslog.filename   = "| /usr/local/lighttpd/bin/rotatelogs /usr/local/lighttpd/logs/access_%Y%m%d.log 86400"

其中rotatelogs直接从apache的bin目录拷贝过来即可。

分享到:
评论

相关推荐

    lighttpd 安装配置

    详细介绍了lighttpd 安装与配置。

    lighttpd配置和启动脚本

    包括lighttpd.conf配置文件以及用于控制web server启动和停止的脚本。

    Linux Lighttpd 配置安装 运行 测试

    在Linux上安装Lighttpd,里面有遇到的一些问题的解决方法,整个安装流程,还有参考网站

    varnish+lighttpd配置

    varnish+lighttpd配置

    lighttpd简单配置

    lighttpd简单配置,希望对新手同志有用!!!

    用于ROR应用的lighttpd配置模板

    里面包含了lighttpd启动程序,lighttpd配置模板以及一个控制lighttpd启动和关闭的脚本。

    lighttpd-1.4.55移植配置与测试.rar

    交叉编译最新版的lighttpd-1.4.55,配置与测试CGI与HTML.内含 lighttpd-1.4.55源码,移植教程,cgi测试代码,html测试代码.测试cgi时,浏览器中应该输入192.168.100.30/cgi-bin/xx.cgi .其中 192.168.100.30为开发板的ip

    lighttpd性能优化

    lighttpd轻量级的HTTP服务器,全面支持fast-cgi

    lighttpd.conf注释

    lighttpd.conf,可以直接使用。带注释。网上搜索的资料,自己加的。可能有人觉得没什么用╮(╯_╰)╭。分享

    简明Windows,lighttpd,fastcgi,php5 Web服务器配置

    NULL 博文链接:https://yeahoo.iteye.com/blog/319066

    CentOS下Lighttpd Web服务器安装与配置方法

    OS: CentOS release 5.5 Lighttpd: 1.4.28 安装 sudo yum install lighttpd.i386 lighttpd-fastcgi.i386 lighttpd-mod_mysql_vhost.i386 运行 检查配置文件 lighttpd -t -f lighttpd.conf 启动lighttpd服务 ...

    Lighttpd源码分析_mobi

    主要内容包括:lighttpd介绍与分析准备工作、lighttpd网络服务主模型、lighttpd数据结构、伸展树、日志系统、文件状态缓存器、配置信息加载、i/o多路复用技术模型、插件链、网络请求服务响应流程、请求响应数据快速...

    phpLight(LightTPD+PHP集成包) v2014

    纯绿色,安装后无需再配置。支持系统服务和非服务两种启动方式,自由切换。一次性安装无需再安装,即使重做系统后亦可使用,直接点启动即可。小巧简易迷你只有14M,非常方便的搭建网站服务器。有专门开发的控制面板...

    ubuntu lighttpd实现websocket

    3、首先配置lighttpd.conf 修改为自己的工作路径 var.server_root = "/home/caoft/lighttpd/lighttpd_websocket/http_server" var.state_dir = "/home/caoft/lighttpd/lighttpd_websocket/http_server" var.home_dir...

    lighttpd源码分析

    网上收集的关于lighttpd代码分析的文章,内容不多。

    LightTPD for windows 1.4.45-x86

    startLighttp.vbs 为一键启动lighttpd和php-cgi的启动脚本,php使用fastcgi host:port形式 test_cgi.cmd 为测试cgi传参数用(如果发现php程序返回No input file specified.说明server.document-root这个目录配置的有...

    LightTPD for windows 1.4.45-x64

    startLighttp.vbs 为一键启动lighttpd和php-cgi的启动脚本,php使用fastcgi host:port形式 test_cgi.cmd 为测试cgi传参数用(如果发现php程序返回No input file specified.说明server.document-root这个目录配置的有...

    三大WEB服务器配置文档

    APACHE服务器安装配置(LAMP) LIGHTTPD服务器安装配置 LIGHTTPD服务状态监控 NGINX服务器安装配置

    phpLight 2013 网上首套LightTPD+PHP集成包

    纯绿色,安装后无需再配置。支持系统服务和非服务两种启动方式,自由切换。 一次性安装无需再安装,即使重做系统后亦可使用,直接点启动即可。 小巧简易迷你只有14M,非常方便的搭建网站服务器。 有专门开发的控制...

Global site tag (gtag.js) - Google Analytics