(转载)轻量级Web服务器Lighttpd的编译及配置(for x86linux)

(转载)http://www.linuxidc.com/Linux/2012-05/60736p3.htm

备注:
PC Linux:Ubuntu-10.10
Linux用户:root
lighttpd版本:1.4.30
gcc版本:4.4.5


1. 编译、安装
1.1. 先到lighttpd官网下载对应版本的软件包:
http://www.lighttpd.net/
我下载的是 lighttpd-1.4.30.tar.gz
1.2. 将压缩包解压到任意目录(我的是 /root/Desktop/common)得到文件夹 lighttpd-1.4.30
1.3. 在文件夹 lighttpd-1.4.30 中创建shell脚本,命名为:configure-x86.sh
1.4. 在shell脚本 configure-x86.sh 中输入如下代码:
#! /bin/sh
./configure --prefix=/opt/web/lighttpd-1.4.30-x86 --host=i686-pc-linux --build=i686-pc-linux --disable-FEATURE --enable-shared --disable-static --disable-lfs --disable-ipv6 --without-PACKAGE --without-valgrind --without-openssl --without-kerberos5 --without-pcre --without-zlib --without-bzip2 --without-lua
1.5. 打开控制台,cd进入 lighttpd-1.4.30 目录
1.6. 给 configure-x86.sh 文件添加可执行属性,执行命令:
chmod +x configure-x86.sh
1.7. 配置lighttpd,执行命令:
./configure-x86.sh
1.8. 编译lighttpd,执行命令:
make
1.9. 安装lighttpd,执行命令:
make install
1.10. 安装完成后,在安装目录 /opt/web/lighttpd-1.4.30-x86 中生成 lib、sbin和share三个文件夹,如下图所示:
 

 


2. 配置
2.1. 在安装目录 /opt/web/lighttpd-1.4.30-x86 中手动创建如下文件夹:cache、cgi-bin、config、log、sockets、upload、vhosts、webpages。如下图所示:
 

 

 2.2. 将源码包中doc/config目录下的config.d、lighttpd.conf和modules.conf复制到安装目录中config文件夹里面,如下图所示:
 


2.3. 修改刚复制过来的lighttpd.conf文件
1)将16行至20行修改为如下褐色加粗字体所示:
var.log_root    = "/opt/web/lighttpd-1.4.30-x86/log"
var.server_root = "/opt/web/lighttpd-1.4.30-x86"
var.state_dir   = "/opt/web/lighttpd-1.4.30-x86"
var.home_dir    = "/opt/web/lighttpd-1.4.30-x86"
var.conf_dir    = "/opt/web/lighttpd-1.4.30-x86/config"
 2)将61行和93行修改为如下褐色加粗字体所示:
var.cache_dir   = server_root + "/cache"
server.use-ipv6 = "disable"
3)将104和105行注释掉,如下所示:
#server.username  = "lighttpd"
#server.groupname = "lighttpd"
4)将115行修改为如下褐色加粗字体所示:
server.document-root = server_root + "/webpages"
5)将127行注释掉,如下所示:
#server.pid-file = state_dir + "/lighttpd.pid"
6)如果不需要查看错误日志文件,可以将141行注释掉,如下所示:
#server.errorlog             = log_root + "/error.log"
7)将152行、158行、191行注释掉,如下所示:
#include "conf.d/access_log.conf"
#include "conf.d/debug.conf"
#server.network-backend = "linux-sendfile"
8)根据系统资源设置207行和225行的数值,本系统的设置分别如下褐色加粗字体所示:
server.max-fds = 256
server.max-connections = 128
9)将314至316行注释掉,如下所示:
#$HTTP["url"] =~ "\.pdf$" {
#  server.range-requests = "disable"
#}
10)将373行修改为如下褐色加粗字体所示:
server.upload-dirs = ( "/opt/web/lighttpd-1.4.30-x86/upload" )


2.4. 修改刚复制过来的modules.conf文件
1)找到43行,将光标定位到逗号后面,回车,插入如下内容:
"mod_alias",
2)使能CGI模块,将138行的注释符去掉,如下所示:
include "conf.d/cgi.conf"


2.5. 修改刚复制过来的conf.d文件夹里面的cgi.conf文件
1)将15至19行这一段配置修改如下:
原文内容:
cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
                               ".cgi" => "/usr/bin/perl",
                               ".rb"  => "/usr/bin/ruby",
                               ".erb" => "/usr/bin/eruby",
                               ".py"  => "/usr/bin/python" )
更改后:
cgi.assign = (".cgi" => "")
#cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
#                               ".cgi" => "/usr/bin/perl",
#                               ".rb"  => "/usr/bin/ruby",
#                               ".erb" => "/usr/bin/eruby",
#                               ".py"  => "/usr/bin/python" )
2)将28行的注释符去掉,如下所示:
alias.url += ( "/cgi-bin" => server_root + "/cgi-bin" )


3. 运行测试
3.1. 在任意地方创建一空白文档,在文档中输入如下HTML代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>lighttpd测试</title>
</head>
<body>
<p>轻量级web服务器lighttpd的编译及配置(for x86-linux)</p>
<hr>
<p>测试页面</p>
</body>
</html>
3.2. 将文档保存为index.html,并复制到安装目录中的webpages文件夹里面,如下图所示:

3.3. 开启命令台,cd进入到lighttpd可执行文件的安装目录:cd /opt/web/lighttpd-1.4.30-x86/sbin/
3.4. 执行命令启动lighttpd服务器:./lighttpd -f ../config/lighttpd.conf ,如下图所示:

 3.5. 启动网页浏览器,如 Google Chrome,输入本机IP地址,回车,即可浏览到刚才创建的主页了,如下图所示:

 3.6. 关闭服务器:killall lighttpd


结束语:
        由于本人移植lighttpd的目的是为了开发嵌入式应用,因此配置文件中的设置都是针对嵌入式系统中有限的资源而作的配置,测试OK后即可把这些配置文件原封不动地复制到开发板直接应用。

原文地址:https://www.cnblogs.com/Robotke1/p/3081095.html