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注重于稳定性和功能,怎么选择还得看具体的应用。

lighttpd服务器404页修改,教你学会Lighttpd的安装配置相关推荐

  1. 阿里云服务器 ECS 部署lamp:centos+apache+mysql+php安装配置方法 (centos7)

    阿里云服务器 ECS 部署lamp:centos+apache+mysql+php安装配置方法 (centos7) 1.效果图 1 2. 部署步骤 1 1. mysql安装附加(centos7) 7 ...

  2. 主机宝服务器默认页修改,主机宝服务器默认页

    主机宝服务器默认页 内容精选 换一换 私网NAT网关创建后,通过添加DNAT规则,则可以通过映射方式将您VPC内的云主机实例对外部私网(IDC或其他VPC)提供服务.云主机的每个端口分别对应一条DNA ...

  3. win10服务器密码怎么修改,教你windows10密码更改

    windows10早早已进入我们的日常生活和工作中,如果掌握了win10使用技巧的方法,例如系统密码的设置与修改,就可以方便使用windows了,如果可以定期修改密码,这可以极大的提升系统和个人信息的 ...

  4. centos 安装配置ftp服务器

    2019独角兽企业重金招聘Python工程师标准>>> vsftpd(Very Secure FTP Daemon)是unix/linux下安全快速的FTP服务器.本文主要记录如何在 ...

  5. OPC服务器软件Kepware Kepserver实现与Mysql数据库连接交互(二)Kepserver软件安装配置

    在上篇教程:OPC服务器软件Kepware Kepserver实现与Mysql数据库连接交互(一)中我们学习了MySQL数据库简介.OPC服务器软件Kepserver软件介绍.MySQL5.5数据库安 ...

  6. 修改服务器404页面,服务器上的404页面做了有什么好处?

    当网站被调整或页面被修改时,将有页面被删除.重命名或移动.此时,虽然相应内容的页面仍然存在于网站中,但它们不能通过使用原始地址访问,或者由于拼写错误的无效链接不能返回到用户想要的信息,需要跳转到第40 ...

  7. 网站404是服务器关闭了吗,什么是404页,对网站有什么影响?

    一.404页是什么 404页面是客户端浏览网页.服务器无法正常提供信息.服务器无法响应.不知道原因时服务器返回的页面. 二. 404页功能 网站设置404页后,当网站出现死链接,搜索引擎蜘蛛抓取网站时 ...

  8. 教你学会七种维护服务器安全最佳技巧

    导读: 你的计算机上是否存在有至关重要的数据,并且不希望它们落入恶人之手呢?当然,它们完全有这种可能 .而且,近些年来,服务器遭受的风险也比以前更大了.越来越多的病毒,心怀不轨的黑客,以及那些商业间谍 ...

  9. GitChat · 软件工程 | 一小时教你学会 Maven 项目的构建与管理

    GitChat 作者:梁鹏举 原文: 一小时教你学会 Maven 项目的构建与管理 关注公众号:GitChat 技术杂谈,一本正经的讲技术 Maven翻译成中文是"专家.内行".M ...

  10. 21天教你学会C++

    21天教你学会C++" 2010年3月30日 陈皓 发表评论 阅读评论 31,048 次点击     下面是一个<Teach Yourself  C++ in 21 Days>的 ...

最新文章

  1. mysql cluster 安装NDB二进制版本
  2. cookie、session、sessionid 与jsessionid
  3. 设置DVWA出现Could not connect to the MySQL service. Please check the config的解决方法,默认登录账号
  4. 操作系统03进程管理Process_Scheduling
  5. C#开发微信公众平台-就这么简单(附Demo)
  6. oracle 二进制运算符,Oracle UNION运算符
  7. ASP.NET Core 中文文档 第二章 指南(4.10)检查自动生成的Detail方法和Delete方法
  8. php5.3.3以后php-fpm进程管理方式
  9. html标签元素分类
  10. rtlab matlab版本,电力电子技术教学中电力仿真软件选择与应用.doc
  11. asc怎么用 linux zip_asc文件扩展名,asc文件怎么打开?
  12. iOS之获取手机DeviceToken,以及苹果测试推送工具Easy APNs Provider
  13. 什么是devicenet跟以太网啥区别
  14. 狂神JAVA博客MySQL_狂神说SpringBoot08:整合Druid
  15. 五笔打字 五笔练习 86编码 字根 五笔字典 拆字 图解
  16. 初中级前端面试复习总结(浏览器、HTTP、前端安全)
  17. win10安装steam有损计算机,win10系统steam磁盘写入错误怎么办 steam磁盘写入错误的解决教程...
  18. agv系统介绍_AGV有什么用
  19. Cisco Packet Tracer(对cisco模拟器的初识+路由基本配置)
  20. 递归算法转化为非递归算法

热门文章

  1. CSS3鼠标悬停图片360度旋转效果
  2. 高德地图完整功能的html,关于高德地图WEB版基础控件的展示
  3. 是时候放弃循环神经网络了
  4. Facebook三大愿景和五大核心价值
  5. 手机端追剧神器,最新最火电影免费看,非常牛批!
  6. python自学篇——PyGame模块的所有功能函数详解
  7. DTOJ3026 geronimo
  8. autojs的使用文档
  9. C语言,最新猴子摘桃(递归方法)
  10. 使用proxychains匿名浏览,清理痕迹(六)