存档

‘LightHttpd’ 分类的存档

lighttpd 配置reload问题

2008年10月28日 Michael Field 3 条评论

lighttpd1.4.x
默认情况下无法使用reload功能,即kill -HUP “PID OF LIGHTTPD” ?
在网上搜索了一番,结果发现可以使用lighttpd的sbin目录下的lighttpd-angel来实现这个reload功能;

方法如下:

下载: code.txt
/pathtolighttpd/sbin/lighttpd-angel -D -f /pathtolighttpd/conf/lighttpd.conf

-D 表示不在后台执行;(默认是在后台执行的)
而这个reload功能一定是要-D参数才能获得支持;

这样新问题就出现;一般管理服务器都是远程登录的ssh中执行&指令的话会导致退出登录ssh后无响应;
可以通过调整延时时间来设定,但毕竟使用起来有点麻烦;

最后执行在前面增加一个nohup工具,总算问题解决了,但毕竟还不完美;

下载: code.txt
nohup /pathtolighttpd/sbin/lighttpd-angel -D -f /pathtolighttpd/conf/lighttpd.conf &

然后再修改lighttpd的service脚本如下:

下载: code.txt
...
prog="lighttpd"
lighttpd="/pathtolighttpd/sbin/lighttpd-angel" #多增加一个lighttpd-angel的变量
lighttpd1="/pathtolighttpd/sbin/lighttpd"
RETVAL=0
 
start() {
        
echo -n $"Starting $prog: "
        #以
lighttpd-angel启动,去掉daemon函数,不然会启动失败,无法和nohup一起使用;
        /
usr/bin/nohup $lighttpd -D -f $LIGHTTPD_CONF_PATH 2 >/dev/null &
        
RETVAL=$?
        
echo
        
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        
return $RETVAL
}
 
stop() {
        
echo -n $"Stopping $prog: "
        
killproc $lighttpd1 #杀进程的依旧是lighttpd
        
RETVAL=$?
        
echo
        
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
        
return $RETVAL
}
 
reload() {
        
echo -n $"Reloading $prog: "
        
killproc $lighttpd -HUP
        
RETVAL=$?
        
echo
        
return $RETVAL
}
....

这样修改完发现每次start的时候不能正常显示[OK];lighttpd-angel开启的时候会调用lighttpd主程序;这样就是lighttpd和lighttpd-angel一起运行,这个也是执行reload必须的;

如果有更好的办法,请留言讨论!
貌似lighttpd1.5.x会解决这个问题。

lighttpd控制fastcgi进程数

2008年9月26日 Johnny Woo 2 条评论

lighttpd默认的fastcgi产生数是8
如果要增加或者减少fastcgi进程数
就需要修改配置文件,进行定制

下载: code.txt
fastcgi.server             = ( ".php" =>
                              
( "localhost" =>
                                
(
                                  
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
                                  
"bin-path" => "/usr/local/php/bin/php-cgi",
                                    
"min-procs" => 1,
                                    
"max-procs" => 1,
                                    
"bin-environment" => (
                                        
"PHP_FCGI_CHILDREN" => "3",
                                    
),
                                    
"bin-copy-environment" => (
                                        
"PATH", "SHELL", "USER"
                                  
),
 
                                    
"idle-timeout" => 20
                                
)
                              
)
                            
)

就是PHP_FCGI_CHILDREN参数.控制fastcgi进程的产生数
有一点要注意
如果使用ea,xcache或者APC等等OPCODE加速器
一定要将max-procs设置为1
否则可能会产生问题.

分类: LightHttpd 标签:

lighttpd防盗链技术的一个变形

2008年9月18日 Tommy 没有评论

lighttpd 中的mod_secure_download.c模块中的防盗链技术大家已经很清楚了,但是这个模块要求会改写一些url的地址,形如:

下载: code.txt
The generated URL has to have the format:
 
<
uri-prefix>/<token>/<timestamp-in-hex>/<rel-path> which looks like "yourserver.com/bf32df9cdb54894b22e09d0ed87326fc/435cc8cc/secure.tar.gz"
 
<
token> is an MD5 of
 
  
1. a secret string (user supplied)
  
2. (rel-path(starts with /)
  
3. (timestamp-in-hex

具体参考:http://trac.lighttpd.net/trac/wiki/Docs%3AModSecDownload

如果有这样的需求,要求不改变原来的下载url,而做到对某些资源进行防盗链呢?
最后我们可以这样做,增加get方法,即是把加密额的部分通过get方法传递给lighttpd的mod_secure_download.c模块
例如,
原来的url: yourserver.com/secure/secure.tar.gz
新的url:yourserver.com/secure/secure.tar.gz?credentials=fhsfhskfaskfhsakfsk2343askfskfsk

这样,我们就做到在不改变原来url的情况下又可以用到mod_secure_download.c模块的防盗链功能

下面要修改mod_secure_download.c模块的源代码,其实很简单,只要熟悉lighttpd的一些常见插件就可以在几分钟内搞定这个功能

下载: code.txt
/*
* if there is a key = md5,
* otherwise sent 403
* */
if (NULL != (get_param = (data_string *)array_get_element(p->get_params, "key"))) {
    /* too short */
    if (get_param->value->used < 2) {
con->http_status = 403;
return HANDLER_FINISHED;
    }

    md5_str = get_param->value->ptr;

    /* check if it is a md5 string */
    if ( strlen(md5_str) != 40 || !is_hex_len(md5_str, 40) ) {
con->http_status = 403;
log_error_write(srv, __FILE__, __LINE__, "ss", "key-md5 invalid:", md5_str);

return HANDLER_FINISHED;
    }
}
else{
    con->http_status = 403;

    return HANDLER_FINISHED;
}

上面的代码就是通过get方法获得加密的字符串,然后下面的代码就是原来lighttpd中的防盗链出来流程

lighttpd的这个加密模块,我个人认为还是有点需要改进的地方
大家也看出来了,对于防盗链,这里采用的是md5单向加密的技术,但是client端向服务器发送的请求加密串是包含时间的(也正是这个时间才是我们用于判断这个url的有效时间,从而达到防盗链的目的),个人觉得可以对明文传输的时间进行一下简单的加密(当然要是可以双向的加密)

还有一点需要注意的地方,就是这个防盗链模块在lighttpd的配置文件中的lighttpd.conf加载顺序是很重要的,
一定要将这个防盗链模块放在mod_flv_streaming.c/mod_h264_streaming.c模块加载之前加载

下载: code.txt
server.modules = ( ..., "mod_secdownload",
mod_flv_streaming”,
"mod_h264_streaming",
 ...
)

不然,防盗链模块会不起作用的,因为flv/h264这些模块里面会有

下载: code.txt
con->file_finished = 1;
return HANDLER_FINISHED;
分类: LightHttpd 标签:

lighttpd支持wordpress伪静态地址

2008年9月12日 Johnny Woo 5 条评论

以前发过nginx支持伪静态的配置
这次换了VPS之后
由于内存比较小.直接用lighttpd来做web service
当中rewrite的配置又有不同
而这次配置.让我也产生了研究rewrite以及redirect差异以及基本原理的想法
下面先给出配置

下载: code.txt
url.rewrite = (
"^/(wp-.+).*/?" => "$0",
"^/(sitemap.xml)" => "$0",
"^/(xmlrpc.php)" => "$0",
"^/(.+)/?$" => "/index.php/$1"
)

会正则的应该能看出什么意思
但是怎样生效.我觉得rewrite和redirect有相当大的差别

分类: LightHttpd 标签:

lighttpd 1.5.0 测试版使用笔记

2008年9月9日 ready 6 条评论

下载地址:http://www.lighttpd.net/download/lighttpd-1.5.0-r1992.tar.gz

lighttpd 1.5.0和lighttpd 1.4.19最大的区别在于1.5.0 增加了异步IO(AIO)的支持。在lighttpd的blog上面有一篇测试文章可以很清楚的看到在磁盘IO方面1.4.19和1.5.0的巨大差别。文章地址:http://blog.lighttpd.net/articles/2006/11/12/lighty-1-5-0-and-linux-aio

经过我们实地使用得到的数据和blog上介绍的数据是相匹配的。不过在实地使用中,当磁盘IO在进行大量读操作的同时又进行大量写操作的时候,服务器会出现死机现象。我这里只有在空白的cache节点开始提供cdn服务的前一两天才会碰到。随着缓存的文件越来越多发生的概率也越来越小。一般缓存两天以后再也没有发生过死机现象。我想这也是为什么cdn服务商会极力推荐你使用预缓存的原因吧。

对于上面提到的死机问题的解决办法是:在提供cache的开始几天里使用lighttpd 1.4.19。等缓存数据基本完成的时候再换成lighttpd 1.5.0。1.4.19由于它的io慢,死机的可能性会大大降低。我们采取这个方法后,开始缓存的几天里没有服务器死机。

软硬件环境:
服务器:dell 1950
操作系统:CentOS 5
磁盘:raid1 sata 1TB*2

跟上面lighttpd blog在磁盘方面情况类似。

分类: LightHttpd 标签:

lighttpd plugin.h代码阅读笔记

2008年9月9日 ready 没有评论

这篇文章是从别人的网站上面保存下来的,忘记那个网站了。对于原作者说声抱歉。
该文件中定义了lighttpd的模块插件结构体。此结构体大量使用了函数指针,对进一步深入了解函数指针很有现在。现在的工作是,解释结构体中每个字段的含义,用处,使用方法。搞清楚插件中几个函数的调用序列,插件中几个函数的返回值对lighttpd有什么影响。

#ifndef _PLUGIN_H_

#define _PLUGIN_H_

#include “base.h”

#include “buffer.h”

//此宏定义服务器函数的通用格式,参数为 server 类型指针,一个 指向模块定义的数据结构的void 类型指针

#define SERVER_FUNC(x) \

static handler_t x(server *srv, void *p_d)

#define CONNECTION_FUNC(x) \

static handler_t x(server *srv, connection *con, void *p_d)

#define INIT_FUNC(x) \

static void *x()

//下面四个是服务器级别的函数

#define FREE_FUNC SERVER_FUNC

#define TRIGGER_FUNC SERVER_FUNC

#define SETDEFAULTS_FUNC SERVER_FUNC

#define SIGHUP_FUNC SERVER_FUNC

//下面五个是连接级别的函数

#define SUBREQUEST_FUNC CONNECTION_FUNC

#define JOBLIST_FUNC CONNECTION_FUNC

#define PHYSICALPATH_FUNC CONNECTION_FUNC

#define REQUESTDONE_FUNC CONNECTION_FUNC

#define URIHANDLER_FUNC CONNECTION_FUNC

#define PLUGIN_DATA size_t id //这个定义的是所有模块插件的内部数据都必须有一个公共字段,这个字段的值由lighttpd统一管理,类似于一个序列值,给每个模块都定义一个ID号。

//模块插件结构体,包含的信息相当的丰富。

typedef struct {

size_t version; //一般写为 : LIGHTTPD_VERSION_ID 什么时候不一样呢。

buffer *name; /* name of the plugin */ //一般写为模块的名字 , 如 mod_skeleton

//下面这些函数指针指向的函数是要编写模块的开发人员实现的,当然,有些是可选的,有些是必须实现的。

void *(* init) (); //在加载当前模块的时候调用,但不是第一个要调用的函数。在此之前会调用 *_plugin_init 函数初始化当前模块。它是第一个实际调用的插件函数。此函数用于初始化模块内部数据结构,此内部数据结构被赋给*plugin_init中设定的data字段了。
handler_t (* set_defaults) (server *srv, void *p_d); //实际调用的第二个插件函数。此函数是配置文件解析入口。它应该传递一个选项参数列表给config_insert_values函数,并且还要检查参数是否有效,如果是无效参数,则需要给该选项参数设置默认值,或者返回错误。
handler_t (* cleanup) (server *srv, void *p_d); //最后一个调用的模块插件函数。用于清理当前模块使用的内存。它在当前模块被卸载的前一该被lighttpd调用。
/* is called … */
handler_t (* handle_trigger) (server *srv, void *p_d); /* once a second */ //每一秒都会调用的插件函数,模块如果不需要此定时器,可以忽略它。
handler_t (* handle_sighup) (server *srv, void *p_d); /* at a signup */ //如果lighttpd收到SIGHUP信号,则它会调用插件中的这个函数,通知插件做相应处理。lighttpd收到这个信号时并不会退出,因而对模块来说可以忽略这个信号。这个函数的调用顺序不定,在模块被加载之后,被卸载之前的任何时刻都可能调用此函数,这依赖于用户行为,用户可能手工向lighttpd发送SIGHUP信号。

handler_t (* handle_uri_raw) (server *srv, connection *con, void *p_d); /* after uri_raw is set */ //在lighttpd 设置了 uri_raw之后被调用。uri_raw是在什么时候设置的呢?
handler_t (* handle_uri_clean) (server *srv, connection *con, void *p_d); /* after uri is set */ //在lighttpd设置了uri.path 之后被调用。uri.path是在什么时候设置的呢?
handler_t (* handle_docroot) (server *srv, connection *con, void *p_d); /* getting the document-root */ //当 lighttpd 需要docroot的时候此函数被调用。 不太明白这个docroot的意思,lighttpd为什么会不定时的需要 docroot 呢?
handler_t (* handle_physical) (server *srv, connection *con, void *p_d); /* mapping url to physical path */ // 在lighttpd设置了physical.path之后被调用。
handler_t (* handle_request_done) (server *srv, connection *con, void *p_d); /* at the end of a request */ //在请求结束的时候被调用,这个时候是否已经处理了请求并将数据发送到了客户端了呢?
handler_t (* handle_connection_close)(server *srv, connection *con, void *p_d); /* at the end of a connection */ //在连接终止的时候被调用。这时候请求的响应数据肯定已经发送到了客户。
handler_t (* handle_joblist) (server *srv, connection *con, void *p_d); /* after all events are handled */ // 当此次请求的连接状态发生变化时此函数被调用。连接状态类型定义: connection_state_t

handler_t (* handle_subrequest_start)(server *srv, connection *con, void *p_d); //在设置了physical.path之后被调用。这和 handle_physical函数有什么区别呢。

/* when a handler for the request
* has to be found
*/
handler_t (* handle_subrequest) (server *srv, connection *con, void *p_d); /* */ //?????
handler_t (* connection_reset) (server *srv, connection *con, void *p_d); /* */ //在每次请求的最后调用。这和 handle_request_close ,handle_request_done 有什么关系,好象是在这两 个调用中间某个时刻调用的???
void *data; //这个是指向模块内部数据结构的指针。

/* dlopen handle */
void *lib; //dlopen 当前模块时返回的指向此模块动态库的指针变量。用于 dlclose, dlsym , dlerror 函数调用。
} plugin;

int plugins_load(server *srv);
void plugins_free(server *srv);

//与结构体中的函数指针对应的函数调用,一一对应。其实模块插件中的函数指针是在下面这些函数中被调用的。
handler_t plugins_call_handle_uri_raw(server *srv, connection *con);
handler_t plugins_call_handle_uri_clean(server *srv, connection *con);
handler_t plugins_call_handle_subrequest_start(server *srv, connection *con);
handler_t plugins_call_handle_subrequest(server *srv, connection *con);
handler_t plugins_call_handle_request_done(server *srv, connection *con);
handler_t plugins_call_handle_docroot(server *srv, connection *con);
handler_t plugins_call_handle_physical(server *srv, connection *con);
handler_t plugins_call_handle_connection_close(server *srv, connection *con);
handler_t plugins_call_handle_joblist(server *srv, connection *con);
handler_t plugins_call_connection_reset(server *srv, connection *con);

handler_t plugins_call_handle_trigger(server *srv);
handler_t plugins_call_handle_sighup(server *srv);

handler_t plugins_call_init(server *srv);
handler_t plugins_call_set_defaults(server *srv);
handler_t plugins_call_cleanup(server *srv);

int config_insert_values_global(server *srv, array *ca, const config_values_t *cv);
int config_insert_values_internal(server *srv, array *ca, const config_values_t *cv);
int config_setup_connection(server *srv, connection *con);
int config_patch_connection(server *srv, connection *con, comp_key_t comp);
int config_check_cond(server *srv, connection *con, data_config *dc);
int config_append_cond_match_buffer(connection *con, data_config *dc, buffer *buf, int n);

#endif

分类: LightHttpd 标签:

IT流言终结者2续篇 :Nginx vs Lighthttpd vs Apache

2008年6月12日 Johnny Woo 没有评论

上篇中我们使用系统的默认配置对nginx,lighthttpd,apache进行测试
在并发量1000时,lighthttpd以及nginx都发生了大量的无法正常抓取页面的错误
在对HTTPD服务器环境加上优化之后

下载: code.txt
ulimit -SHn 51200

nginx和lighthttpd的限制被解除
经过优化之后
测试结果如下
1. Nginx
1000并发数

下载: code.txt
1000 fetches, 1000 max parallel, 2.23782e+08 bytes, in 21.3699 seconds
223782 mean bytes/connection
46.7947 fetches/sec, 1.04718e+07 bytes/sec
msecs/connect: 1321.52 mean, 21002.3 max, 0.215 min
msecs/first-response: 438.404 mean, 2718.81 max, 0.471 min
HTTP response codes:
 
code 200 -- 1000

2.Lighthttpd

下载: code.txt
1000 fetches, 1000 max parallel, 2.23782e+08 bytes, in 22.0106 seconds
223782 mean bytes/connection
45.4327 fetches/sec, 1.0167e+07 bytes/sec
msecs/connect: 1888.67 mean, 21028.2 max, 0.206 min
msecs/first-response: 386.335 mean, 2322.46 max, 0.678 min
HTTP response codes:
 
code 200 -- 1000

3.Apache 1.x

下载: code.txt
1000 fetches, 1000 max parallel, 2.15278e+08 bytes, in 21.0746 seconds
215278 mean bytes/connection
47.4505 fetches/sec, 1.02151e+07 bytes/sec
msecs/connect: 1110.12 mean, 3367.64 max, 0.271 min
msecs/first-response: 7236.8 mean, 18910.1 max, 1.419 min
38 bad byte counts
HTTP response codes:
 
code 200 -- 962

4.Apache 2.x

下载: code.txt
1000 fetches, 999 max parallel, 2.23782e+08 bytes, in 24.6054 seconds
223782 mean bytes/connection
40.6415 fetches/sec, 9.09484e+06 bytes/sec
msecs/connect: 3291.74 mean, 9352.51 max, 0.201 min
msecs/first-response: 5074 mean, 15275.8 max, 1.493 min
HTTP response codes:
 
code 200 -- 1000

提高了系统处理能力之后
Nginx以及Lighthttpd的表现有着翻天覆地的变化
不论是请求的处理能力还是出错率
都较Apache有很大的提升
看来Nginx以及Lighthttpd在负载量提高的时候
能够用尽系统所有的能力
例如文件的并行处理能力
而Apache这时候反而由于同时处理量变大而不堪压力

结论
1.系统优化与否对于Nginx以及Lighthttpd有着至关重要的影响.只适用系统默认状态是无法适应Nginx以及Lighthttpd的要求的.

分类: Apache, LightHttpd, Nginx 标签:

IT流言终结者2:Nginx vs Lighthttpd vs Apache

2008年6月12日 Johnny Woo 1 条评论

和以往一样,本次测试均使用默认配置
不对内核以及应用程序做任何优化
配置文件优先采用程序自带的默认配置,
在没有默认配置的前提下,使用最简化的配置文件

平台
WEB:
CentOS 5.1 最小化安装
浪潮NF180
Xeon 2.8
1G RAM
73G SCSI

Nginx 0.6.31
Apache 1.3.41
Apache 2.2.8
Lighthttpd 1.4.19

CLIENT:
CentOS 5.1 最小化安装
浪潮NF260
Xeon 2.4
512M RAM
36G SCSI

http_load-12mar2006

SWITCH:
DLINK DES 1024R+

1.Nginx 0.6.31
编译参数

下载: code.txt
<?php
./
configure --prefix=/usr/local/nginx

配置文件

下载: code.txt
worker_processes  10;
events {
    
worker_connections  1024;
}
http {
    
include       mime.types;
    
default_type  application/octet-stream;
    
sendfile        on;
    
keepalive_timeout  65;
    
server {
        
listen       80;
        
server_name  localhost;
        
location / {
            
root   html;
            
index  index.html index.htm;
        
}
        
error_page   500 502 503 504  /50x.html;
        
location = /50x.html {
            
root   html;
        
}
    
}
}

2.Lighthttpd 1.4.19
编译参数

下载: code.txt
<?php
./
configure --prefix=/usr/local/lighthttpd

配置文件

下载: code.txt
server.modules              = (
                                
"mod_accesslog" )
 
server.document-root        = "/var/www/html/"
 
server.errorlog             = "/var/log/lighttpd/error.log"
 
index-file.names            = ( "index.php", "index.html",
                                
"index.htm", "default.htm" )
 
mimetype.assign             = (
 
".pdf"          =>      "application/pdf",
 
".sig"          =>      "application/pgp-signature",
 
".spl"          =>      "application/futuresplash",
 
".class"        =>      "application/octet-stream",
 
".ps"           =>      "application/postscript",
 
".torrent"      =>      "application/x-bittorrent",
 
".dvi"          =>      "application/x-dvi",
 
".gz"           =>      "application/x-gzip",
 
".pac"          =>      "application/x-ns-proxy-autoconfig",
 
".swf"          =>      "application/x-shockwave-flash",
 
".tar.gz"       =>      "application/x-tgz",
 
".tgz"          =>      "application/x-tgz",
 
".tar"          =>      "application/x-tar",
 
".zip"          =>      "application/zip",
 
".mp3"          =>      "audio/mpeg",
 
".m3u"          =>      "audio/x-mpegurl",
 
".wma"          =>      "audio/x-ms-wma",
 
".wax"          =>      "audio/x-ms-wax",
 
".ogg"          =>      "application/ogg",
 
".wav"          =>      "audio/x-wav",
 
".gif"          =>      "image/gif",
 
".jar"          =>      "application/x-java-archive",
 
".jpg"          =>      "image/jpeg",
 
".jpeg"         =>      "image/jpeg",
 
".png"          =>      "image/png",
 
".xbm"          =>      "image/x-xbitmap",
 
".xpm"          =>      "image/x-xpixmap",
 
".xwd"          =>      "image/x-xwindowdump",
 
".css"          =>      "text/css",
 
".html"         =>      "text/html",
 
".htm"          =>      "text/html",
 
".js"           =>      "text/javascript",
 
".asc"          =>      "text/plain",
 
".c"            =>      "text/plain",
 
".cpp"          =>      "text/plain",
 
".log"          =>      "text/plain",
 
".conf"         =>      "text/plain",
 
".text"         =>      "text/plain",
 
".txt"          =>      "text/plain",
 
".dtd"          =>      "text/xml",
 
".xml"          =>      "text/xml",
 
".mpeg"         =>      "video/mpeg",
 
".mpg"          =>      "video/mpeg",
 
".mov"          =>      "video/quicktime",
 
".qt"           =>      "video/quicktime",
 
".avi"          =>      "video/x-msvideo",
 
".asf"          =>      "video/x-ms-asf",
 
".asx"          =>      "video/x-ms-asf",
 
".wmv"          =>      "video/x-ms-wmv",
 
".bz2"          =>      "application/x-bzip",
 
".tbz"          =>      "application/x-bzip-compressed-tar",
 
".tar.bz2"      =>      "application/x-bzip-compressed-tar",
 
# default mime type
 
""              =>      "application/octet-stream",
 
)
 
accesslog.filename          = "/var/log/lighttpd/access.log"
 
url.access-deny             = ( "~", ".inc" )
 
$HTTP["url"] =~ "\.pdf$" {
 
server.range-requests = "disable"
}
 
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

3.Apache 1.3.41
编译参数

下载: code.txt
<?php
./
configure --prefix=/usr/local/apache1.3.41

配置文件

下载: code.txt
ServerType standalone
ServerRoot "/usr/local/apache1.3.41"
PidFile /usr/local/apache1.3.41/logs/httpd.pid
ScoreBoardFile /usr/local/apache1.3.41/logs/httpd.scoreboard
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
MinSpareServers 5
MaxSpareServers 10
StartServers 5
MaxClients 150
MaxRequestsPerChild 0
Port 80
User nobody
Group nobody
ServerAdmin root@test1.hiadmin.com
DocumentRoot "/var/www/html"
<
directory />
    
Options FollowSymLinks
    
AllowOverride None
</
directory>
<
directory "/var/www/html">
 
    
Options Indexes FollowSymLinks MultiViews
 
    
AllowOverride None
 
    
Order allow,deny
    
Allow from all
</
directory>
 
<
ifModule mod_userdir.c>
    
UserDir public_html
</
ifModule>
 
<
ifModule mod_dir.c>
    
DirectoryIndex index.html
</
ifModule>
 
AccessFileName .htaccess
 
<
files ~ "^\.ht">
    
Order allow,deny
    
Deny from all
    
Satisfy All
</
files>
 
UseCanonicalName On
 
<
ifModule mod_mime.c>
    
TypesConfig /usr/local/apache1.3.41/conf/mime.types
</
ifModule>
 
DefaultType text/plain
 
<
ifModule mod_mime_magic.c>
    
MIMEMagicFile /usr/local/apache1.3.41/conf/magic
</
ifModule>
 
HostnameLookups Off
 
ErrorLog /usr/local/apache1.3.41/logs/error_log
 
LogLevel warn
 
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
 
CustomLog /usr/local/apache1.3.41/logs/access_log common
 
ServerSignature On
 
<
ifModule mod_alias.c>
 
    
Alias /icons/ "/usr/local/apache1.3.41/icons/"
 
    <
directory "/usr/local/apache1.3.41/icons">
        
Options Indexes MultiViews
        
AllowOverride None
        
Order allow,deny
        
Allow from all
    </
directory>
 
    
Alias /manual/ "/usr/local/apache1.3.41/htdocs/manual/"
 
    <
directory "/usr/local/apache1.3.41/htdocs/manual">
        
Options Indexes FollowSymlinks MultiViews
        
AllowOverride None
        
Order allow,deny
        
Allow from all
    </
directory>
 
    
ScriptAlias /cgi-bin/ "/usr/local/apache1.3.41/cgi-bin/"
 
    <
directory "/usr/local/apache1.3.41/cgi-bin">
        
AllowOverride None
        
Options None
        
Order allow,deny
        
Allow from all
    </
directory>
 
</
ifModule>
<
ifModule mod_autoindex.c>
 
    
IndexOptions FancyIndexing
 
    
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
 
    
AddIconByType (TXT,/icons/text.gif) text/*
    AddIconByType (IMG,/icons/image2.gif) image/*
    AddIconByType (SND,/icons/sound2.gif) audio/*
    AddIconByType (VID,/icons/movie.gif) video/*
 
    AddIcon /icons/binary.gif .bin .exe
    AddIcon /icons/binhex.gif .hqx
    AddIcon /icons/tar.gif .tar
    AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
    AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
    AddIcon /icons/a.gif .ps .ai .eps
    AddIcon /icons/layout.gif .html .shtml .htm .pdf
    AddIcon /icons/text.gif .txt
    AddIcon /icons/c.gif .c
    AddIcon /icons/p.gif .pl .py
    AddIcon /icons/f.gif .for
    AddIcon /icons/dvi.gif .dvi
    AddIcon /icons/uuencoded.gif .uu
    AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
    AddIcon /icons/tex.gif .tex
    AddIcon /icons/bomb.gif core
 
    AddIcon /icons/back.gif ..
    AddIcon /icons/hand.right.gif README
    AddIcon /icons/folder.gif ^^DIRECTORY^^
    AddIcon /icons/blank.gif ^^BLANKICON^^
 
    DefaultIcon /icons/unknown.gif
 
    ReadmeName README.html
    HeaderName HEADER.html
 
    IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
 
</ifModule>
<ifModule mod_mime.c>
 
    AddLanguage da .dk
    AddLanguage nl .nl
    AddLanguage en .en
    AddLanguage et .ee
    AddLanguage fr .fr
    AddLanguage de .de
    AddLanguage el .el
    AddLanguage he .he
    AddCharset ISO-8859-8 .iso8859-8
    AddLanguage it .it
    AddLanguage ja .ja
    AddCharset ISO-2022-JP .jis
    AddLanguage kr .kr
    AddCharset ISO-2022-KR .iso-kr
    AddLanguage nn .nn
    AddLanguage no .no
    AddLanguage pl .po
    AddCharset ISO-8859-2 .iso-pl
    AddLanguage pt .pt
    AddLanguage pt-br .pt-br
    AddLanguage ltz .lu
    AddLanguage ca .ca
    AddLanguage es .es
    AddLanguage sv .sv
    AddLanguage cs .cz .cs
    AddLanguage ru .ru
    AddLanguage zh-TW .zh-tw
    AddCharset Big5         .Big5    .big5
    AddCharset WINDOWS-1251 .cp-1251
    AddCharset CP866        .cp866
    AddCharset ISO-8859-5   .iso-ru
    AddCharset KOI8-R       .koi8-r
    AddCharset UCS-2        .ucs2
    AddCharset UCS-4        .ucs4
    AddCharset UTF-8        .utf8
 
    <ifModule mod_negotiation.c>
        LanguagePriority en da nl et fr de el it ja kr no pl pt pt-br ru ltz ca es sv tw
    </ifModule>
 
    AddType application/x-tar .tgz
 
    AddEncoding x-compress .Z
    AddEncoding x-gzip .gz .tgz
 
</ifModule>
 
<ifModule mod_setenvif.c>
 
    BrowserMatch "RealPlayer 4\.0" force-response-1.0
    BrowserMatch "Java/1\.0" force-response-1.0
    BrowserMatch "JDK/1\.0" force-response-1.0
 
</ifModule>
?>

4.Apache 2.2.8
编译参数

下载: code.txt
<?php
./
configure --prefix=/usr/local/apache2.2.8

配置文件

下载: code.txt
ServerRoot "/usr/local/apache2.2.8"
Listen 80
 
<
ifModule !mpm_netware_module>
<
ifModule !mpm_winnt_module>
User nobody
Group nobody
 
</
ifModule>
</
ifModule>
 
ServerAdmin you@example.com
 
DocumentRoot "/var/www/html"
 
<
directory />
    
Options FollowSymLinks
    
AllowOverride None
    
Order deny,allow
    
Deny from all
</
directory>
 
<
directory "/var/www/html">
    
Options Indexes FollowSymLinks
    
AllowOverride None
    
Order allow,deny
    
Allow from all
 
</
directory>
 
<
ifModule dir_module>
    
DirectoryIndex index.html
</
ifModule>
 
<
filesMatch "^\.ht">
    
Order allow,deny
    
Deny from all
    
Satisfy All
</
filesMatch>
 
ErrorLog "logs/error_log"
 
LogLevel warn
 
<
ifModule log_config_module>
    
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    
LogFormat "%h %l %u %t \"%r\" %>s %b" common
 
    <
ifModule logio_module>
      
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </
ifModule>
 
    
CustomLog "logs/access_log" common
</
ifModule>
 
<
ifModule alias_module>
    
ScriptAlias /cgi-bin/ "/usr/local/apache2.2.8/cgi-bin/"
</
ifModule>
 
<
ifModule cgid_module>
</
ifModule>
 
<
directory "/var/www/html">
    
AllowOverride None
    
Options None
    
Order allow,deny
    
Allow from all
</
directory>
 
DefaultType text/plain
 
<
ifModule mime_module>
    
TypesConfig conf/mime.types
 
    
AddType application/x-compress .Z
    
AddType application/x-gzip .gz .tgz
 
</
ifModule>
 
<
ifModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</
ifModule>

测试结果
1.Nginx 0.6.31
200并发

下载: code.txt
<?php
./
http_load -parallel 200 -fetches 1000 urls
下载: code.txt
1000 fetches, 200 max parallel, 2.23782e+08 bytes, in 19.0757 seconds
223782 mean bytes/connection
52.4228 fetches/sec, 1.17313e+07 bytes/sec
msecs/connect: 318.028 mean, 9293.85 max, 0.183 min
msecs/first-response: 278.832 mean, 2858.73 max, 0.489 min
HTTP response codes:
 
code 200 -- 1000

500并发

下载: code.txt
<?php
./
http_load -parallel 500 -fetches 1000 urls
下载: code.txt
1000 fetches, 500 max parallel, 2.23782e+08 bytes, in 19.0797 seconds
223782 mean bytes/connection
52.4119 fetches/sec, 1.17288e+07 bytes/sec
msecs/connect: 243.77 mean, 9104.99 max, 0.194 min
msecs/first-response: 307.939 mean, 2279.38 max, 0.514 min
HTTP response codes:
 
code 200 -- 1000

1000并发

下载: code.txt
<?php
./
http_load -parallel 1000 -fetches 1000 urls
下载: code.txt
1000 fetches, 1000 max parallel, 1.41278e+08 bytes, in 12.0671 seconds
141278 mean bytes/connection
82.8699 fetches/sec, 1.17077e+07 bytes/sec
msecs/connect: 692.526 mean, 3251.55 max, 0.265 min
msecs/first-response: 356.194 mean, 2131.45 max, 0.465 min
631 bad byte counts
HTTP response codes:
 
code 200 -- 631
 
code 500 -- 369

2.Lighthttpd 1.4.19
200并发

下载: code.txt
<?php
./
http_load -parallel 200 -fetches 1000 urls
下载: code.txt
1000 fetches, 200 max parallel, 2.23782e+08 bytes, in 19.0897 seconds
223782 mean bytes/connection
52.3842 fetches/sec, 1.17226e+07 bytes/sec
msecs/connect: 354.108 mean, 3638.78 max, 0.143 min
msecs/first-response: 235.485 mean, 3029.56 max, 1.997 min
HTTP response codes:
 
code 200 -- 1000

500并发

下载: code.txt
<?php
./
http_load -parallel 500 -fetches 1000 urls
下载: code.txt
1000 fetches, 500 max parallel, 2.23782e+08 bytes, in 19.0725 seconds
223782 mean bytes/connection
52.4315 fetches/sec, 1.17332e+07 bytes/sec
msecs/connect: 287.275 mean, 9455.62 max, 0.224 min
msecs/first-response: 257.751 mean, 2249.71 max, 0.97 min
HTTP response codes:
 
code 200 -- 1000

1000并发

下载: code.txt
<?php
./
http_load -parallel 1000 -fetches 1000 urls
下载: code.txt
1000 fetches, 1000 max parallel, 2.1774e+08 bytes, in 22.7961 seconds
217740 mean bytes/connection
43.8672 fetches/sec, 9.55164e+06 bytes/sec
msecs/connect: 1460.29 mean, 21008.3 max, 0.214 min
msecs/first-response: 2799.52 mean, 22539.3 max, 1.229 min
973 bad byte counts
HTTP response codes:
 
code 200 -- 977

3.Apache 1.3.41
200并发

下载: code.txt
<?php
./
http_load -parallel 200 -fetches 1000 urls
下载: code.txt
1000 fetches, 200 max parallel, 2.23782e+08 bytes, in 19.0731 seconds
223782 mean bytes/connection
52.4299 fetches/sec, 1.17329e+07 bytes/sec
msecs/connect: 276.673 mean, 9453.83 max, 0.243 min
msecs/first-response: 1599.88 mean, 8320.12 max, 1.113 min
HTTP response codes:
 
code 200 -- 1000

500并发

下载: code.txt
<?php
./
http_load -parallel 500 -fetches 1000 urls
下载: code.txt
1000 fetches, 500 max parallel, 2.23782e+08 bytes, in 19.0728 seconds
223782 mean bytes/connection
52.4307 fetches/sec, 1.1733e+07 bytes/sec
msecs/connect: 422.419 mean, 9415.94 max, 0.193 min
msecs/first-response: 4767.44 mean, 18611.4 max, 0.88 min
HTTP response codes:
 
code 200 -- 1000

1000并发

下载: code.txt
<?php
./
http_load -parallel 1000 -fetches 1000 urls
下载: code.txt
1000 fetches, 1000 max parallel, 2.17516e+08 bytes, in 42.654 seconds
217516 mean bytes/connection
23.4444 fetches/sec, 5.09954e+06 bytes/sec
msecs/connect: 1074.78 mean, 3355.42 max, 0.265 min
msecs/first-response: 8056.64 mean, 20524.4 max, 0.874 min
28 bad byte counts
HTTP response codes:
 
code 200 -- 972

4.Apache 2.2.8
200并发

下载: code.txt
<?php
./
http_load -parallel 200 -fetches 1000 urls
下载: code.txt
1000 fetches, 200 max parallel, 2.23782e+08 bytes, in 19.0764 seconds
223782 mean bytes/connection
52.4207 fetches/sec, 1.17308e+07 bytes/sec
msecs/connect: 244.063 mean, 9526.98 max, 0.175 min
msecs/first-response: 1489.62 mean, 8591.23 max, 1.88 min
HTTP response codes:
 
code 200 -- 1000

500并发

下载: code.txt
<?php
./
http_load -parallel 500 -fetches 1000 urls
下载: code.txt
1000 fetches, 500 max parallel, 2.21992e+08 bytes, in 21.037 seconds
221992 mean bytes/connection
47.5352 fetches/sec, 1.05524e+07 bytes/sec
msecs/connect: 253.137 mean, 3475.19 max, 0.159 min
msecs/first-response: 3842.25 mean, 16118.2 max, 1.163 min
8 bad byte counts
HTTP response codes:
 
code 200 -- 992

1000并发

下载: code.txt
<?php
./
http_load -parallel 1000 -fetches 1000 urls
下载: code.txt
1000 fetches, 1000 max parallel, 2.1774e+08 bytes, in 26.5296 seconds
217740 mean bytes/connection
37.6938 fetches/sec, 8.20745e+06 bytes/sec
msecs/connect: 1384.75 mean, 9128.98 max, 0.245 min
msecs/first-response: 6792.88 mean, 24075.5 max, 1.493 min
27 bad byte counts
HTTP response codes:
 
code 200 -- 973

在200以及500并发的情况下
我们可以看到4个httpd软件并没有本质差别
但是当并发数达到1000
我们发现lighthttpd的错误率最高,nginx紧随其后,再仔细分析数据
我们可以发现nginx的631次获取中,有631次count byte wrong,也就是说全部出错
而lighthttpd的977此获取中有973次是出错
nginx更差一些
当然这个差距.可能由于nginx以及lighthttpd的默认timeout值有关
apache作为追求稳定的服务软件,其默认timeout值比较大
策略上的差异导致性能上以及稳定性上的差异
apache 2.2.8在500并发数时就发生了错误,而且在之后的几次测试中,也均发生错误
不论是重启服务器还是其他措施,apahce2在500并发数的表现下均无法令人满意
但是其在1000并发数下的性能表现,在不增加错误数的前提下,比apache 1.3.41有着很大的提高

结论
1.nginx以及lighthttpd的性能在默认配置情况下遇到大流量将会发生无法服务的情况
2.apache 2.x的版本其压力/性能表现呈线性,更适合大型网站使用.在压力不是很大的情况下,可能apache 1.x更适合.

分类: Apache, LightHttpd, Nginx 标签:

轻量级HTTP服务程序比较

2008年4月11日 Johnny Woo 没有评论

自从yutobe爆了他们所用的http服务是lighthttpd而非传统apache之后
轻量级http服务以其极高的分发处理能力而受到各大高流量网站的注意
而这方面的程序也越来越多
目前主要的有几种
lighthttpd
yaws
ngnix
fnord
ghttpd

分类: Apache, LightHttpd, Nginx 标签: