Lighttpd 的安装配置
2006-07-16 01:06
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 1.4.11 mod_ssi 补丁
lighttpd 1.4.11 的 mod_ssi 默认情况下不支持以下ssi语法:
有两件文件test.shtml和header.shtml,test.shtml中设置了文章标题变量doc_title,然后再include header.shtml,headers.shtml再根据doc_title的值,显示网页标题,具体内容如下:
test.shtml

header.shtml

test

这两个文件在apache中工作正常,但在lighttpd 1.4.11上却不能正常工作,在移植CNFUG.org的服务到lighttpd的时候,就遇到这个问题,同时发现 mod_ssi 也不支持嵌套 #include。后来根据lighttpd 1.4.11的代码,写了一个小patch for mod_ssi,解决了以上的问题,附代码:
(注:嵌套 #include 的代码由 marc@r4l.com's 提供,在此感谢marc!代码也可以从这儿获得:http://matthew.cnfug.org/patch/mod_ssi.c.patch)
--- mod_ssi.c Sun Apr 2 01:20:30 2006
+++ mod_ssi.c.modify Sun Apr 2 01:21:05 2006
@@ -36,6 +36,9 @@
#include 
#endif
+/* determine if process finished */
+int h_finished = 0;
+
/* init the plugin data */
INIT_FUNC(mod_ssi_init) {
plugin_data *p;
@@ -57,7 +60,7 @@ FREE_FUNC(mod_ssi_free) {
UNUSED(srv);
if (!p) return HANDLER_GO_ON;

+
if (p->config_storage) {
size_t i;
for (i = 0; i config_context->used; i++) {
@@ -286,6 +289,37 @@ static int build_ssi_cgi_vars(server *sr
return 0;
}
+URIHANDLER_FUNC(mod_ssi_physical_path) {
+ plugin_data *p = p_d;
+ size_t k;

+ if (con->physical.path->used == 0) return HANDLER_GO_ON;
+
+ con->loops_per_request++;

+ mod_ssi_patch_connection(srv, con, p);

+ for (k = 0; k conf.ssi_extension->used; k++) {
+ data_string *ds = (data_string *)p->conf.ssi_extension->data[k];

+ if (ds->value->used == 0) continue;

+ if (buffer_is_equal_right_len(con->physical.path, ds->value, ds->value->used - 1)) {
+ /* handle ssi-request */

+ if (mod_ssi_handle_request(srv, con, p)) {
+ /* on error */
+ con->http_status = 500;
+ }

+ return HANDLER_FINISHED;
+ }
+ }

+ /* not found */
+ return HANDLER_GO_ON;
+}
+
static int process_ssi_stmt(server *srv, connection *con, plugin_data *p, 
const char **l, size_t n) {
size_t i, ssicmd = 0;
@@ -467,7 +501,11 @@ static int process_ssi_stmt(server *srv,
if (NULL != (ds = (data_string *)array_get_element(p->ssi_cgi_env, var_val))) {
buffer_copy_string_buffer(b, ds->value);
} else {
- buffer_copy_string(b, "(none)");
+ if (NULL != (ds = (data_string *)array_get_element(p->ssi_vars, var_val))) {
+ buffer_copy_string_buffer(b, ds->value);
+ } else {
+ buffer_copy_string(b, "(none)");
+ }
}
break;
@@ -481,6 +519,7 @@ static int process_ssi_stmt(server *srv,
const char * file_path = NULL, *virt_path = NULL;
struct stat st;
char *sl;
+ buffer *tmp;
for (i = 2; i write_queue, p->stat_fn, 0, st.st_size);
+ /* do recursive SSI expansion */
+ /* prevents infinite loop */
+ if (con->loops_per_request > 25 || buffer_is_equal(con->physical.path, p->stat_fn)) {
+ buffer_copy_string(srv->tmp_buf, "");
+ chunkqueue_append_buffer(con->write_queue, srv->tmp_buf);
+ break;
+ }
+
+ tmp = buffer_init();
+ buffer_copy_string_buffer(tmp, con->physical.path); /* save path of current document */
+ buffer_copy_string_buffer(con->physical.path, p->stat_fn); /* next sub-document to parse */
+ if (mod_ssi_physical_path(srv, con, p) != HANDLER_FINISHED) {
+ /* the document was not processed, so write it as is */
+ chunkqueue_append_file(con->write_queue, con->physical.path, 0, st.st_size);
+ } else {
+ h_finished = 1; 
+ }
+ buffer_copy_string_buffer(con->physical.path, tmp); /* restore saved path */
+ buffer_free(tmp);

break;
}
} else {
@@ -897,7 +955,11 @@ static int mod_ssi_handle_request(server
/* get a stream to the file */
- array_reset(p->ssi_vars);
+ if (h_finished == 1)
+ {
+ array_reset(p->ssi_vars);
+ h_finished = 0;
+ }
array_reset(p->ssi_cgi_env);
buffer_copy_string(p->timefmt, "%a, %d %b %Y %H:%M:%S %Z");
p->sizefmt = 0;
@@ -1038,35 +1100,6 @@ static int mod_ssi_patch_connection(serv
}
#undef PATCH
-URIHANDLER_FUNC(mod_ssi_physical_path) {
- plugin_data *p = p_d;
- size_t k;

- if (con->physical.path->used == 0) return HANDLER_GO_ON;

- mod_ssi_patch_connection(srv, con, p);

- for (k = 0; k conf.ssi_extension->used; k++) {
- data_string *ds = (data_string *)p->conf.ssi_extension->data[k];

- if (ds->value->used == 0) continue;

- if (buffer_is_equal_right_len(con->physical.path, ds->value, ds->value->used - 1)) {
- /* handle ssi-request */

- if (mod_ssi_handle_request(srv, con, p)) {
- /* on error */
- con->http_status = 500;
- }

- return HANDLER_FINISHED;
- }
- }

- /* not found */
- return HANDLER_GO_ON;
-}
-
/* this function is called at dlopen() time and inits the callbacks */
int mod_ssi_plugin_init(plugin *p) {
@@ -1082,3 +1115,4 @@ int mod_ssi_plugin_init(plugin *p) {
return 0;
}
+

用法:
$ cd lighttpd-1.4.11/src
$ patch

转载于:https://www.cnblogs.com/wangbin/archive/2009/06/18/1505473.html

Lighttpd 的安装配置(web服务器软件)相关推荐

  1. Ubuntu下Apache的安装和配置——web服务器

    Apache2 <百度百科 > Apache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之 ...

  2. 教你如何在云服务器上安装并配置web服务器(这里以nginx服务器为例,操作系统linux)

    前言: 这里以git bash 工具为例,当然你可以直接用puTTY或者Xshell链接到服务器,用FileZilla 上传文件. 一.连接服务器 ssh root@你的远程ip地址. 二.查看版本 ...

  3. MyEclipse网站服务器,myeclipse配置web服务器

    myeclipse配置web服务器 内容精选 换一换 简要介绍uWSGI是一个Web服务器,它实现了WSGI协议.uwsgi.http等协议.Nginx中HttpUwsgiModule的作用是与uWS ...

  4. xp系统web服务器搭建教程,Windows_XP配置WEB服务器教程(图)

    indows_XP配置WEB服务器教程 Web站点配置 现在能架起WEB服务的软件还是很多的,不过最简单最好用的还是IIS.有的朋友可能还不了解什么是IIS,简单来说,IIS的全称是Internet ...

  5. [JavaWeb-Tomcat]web服务器软件_Tomcat介绍

    Tomcat:web服务器软件 1. 下载:http://tomcat.apache.org/2. 安装:解压压缩包即可.* 注意:安装目录建议不要有中文和空格3. 卸载:删除目录就行了4. 启动:* ...

  6. Nginx实战基础篇一 源码包编译安装部署web服务器

    Nginx实战基础篇一 源码包编译安装部署web服务器 版权声明: 本文遵循"署名非商业性使用相同方式共享 2.5 中国大陆"协议 您可以自由复制.发行.展览.表演.放映.广播或通 ...

  7. nas服务器改成网站,nas配置web服务器

    nas配置web服务器 内容精选 换一换 华为云帮助中心,为用户提供产品简介.价格说明.购买指南.用户指南.API参考.最佳实践.常见问题.视频帮助等技术文档,帮助您快速上手使用华为云服务. 云耀云服 ...

  8. java day37【web相关概念回顾 、web服务器软件:Tomcat 、Servlet入门学习】

    第一章  web相关概念回顾 1. 软件架构 1. C/S:客户端/服务器端 2. B/S:浏览器/服务器端 2. 资源分类 1. 静态资源:所有用户访问后,得到的结果都是一样的,称为静态资源.静态资 ...

  9. 虚拟机2012搭建DNS服务器,Windows Server2012 安装配置DNS服务器方法详解

    Windows Server2012 安装配置DNS服务器方法详解 在云服务器 Windows Server2012 上安装配置DNS服务器方法,安装与配置非常简单,在这里写个完整教程方便大家查询 一 ...

最新文章

  1. myeclipse 修改模板
  2. 移动端数据java后台接收
  3. Python学习笔记(六)if判断语句
  4. 交叉编译指定运行时库路径_运行时vs编译时类路径
  5. crt 8.7.3 黑暗模式_科技有意思 | 黑黑黑黑黑黑黑黑暗模式
  6. 服务器proc文件,特殊文件系统proc
  7. Packet Capture
  8. mysql execution plan_MySQL Execution Plan--NOT IN查询
  9. Atmega128 AVR Studio熔丝位(Fuse)设置
  10. paypal php 接口文档,paypal接口开发记录
  11. 【教程】如何批量制作线刷包和卡刷包
  12. r语言 rgl 强制过程中_R语言中编写最小工作示例(MWRE)
  13. 10000个怎么用js写 创建li_JavaScript给每一个li节点绑定点击事件的实现方法
  14. 电商项目 的业务逻辑与相关要点
  15. Cortex-A 架构
  16. 图标快速定位工具 ElementUI FontAwesome iView
  17. hibernate 检索策略
  18. 《第五项修炼,学习型组织的艺术与实践》读书笔记
  19. 聊天软件端到端加密使用的什么算法?是否能防止第三方抓包软件?
  20. Pdf.js 解决电子印章问题

热门文章

  1. jQuery---过滤选择器
  2. 根据 设备名(br0/eth0/em0)称获取 当前机器的IP地址与子网掩码信息
  3. 分布式资本沈波:未来区块链杀手级应用将出现在“+区块链”
  4. SpringMVC视图解析器(转)
  5. HDUOJ---1879 继续畅通工程
  6. Getting Started with the Table Component
  7. 北向资金运作akshare
  8. JAVA如何取得空list成员类型_String 类型的List作为一个成员变量保存,保存成功后取对象时报空指针...
  9. pmp思维导图 第六版_PMP考试技巧攻略(上)
  10. 面试之 Redis汇总