| Subcribe via RSS

Nginx支持URL静态化

6月 17th, 2008 | No Comments | Posted in Nginx < by Johnny Woo >
location / {
        
index index.html index.php;
        
if (-f $request_filename/index.html){
            
rewrite (.*) $1/index.html break;
        
}
        
if (-f $request_filename/index.php){
            
rewrite (.*) $1/index.php;
        
}
        
if (!-f $request_filename){
            
rewrite (.*) /index.php;
        
}
    
}
阅读内文

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

6月 12th, 2008 | No Comments | Posted in Apache, LightHttpd, Nginx < by Johnny Woo >

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

ulimit -SHn 51200

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

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

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

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

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的要求的.

阅读内文

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

6月 12th, 2008 | No Comments | Posted in Apache, LightHttpd, Nginx < by Johnny Woo >

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

平台
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
编译参数

<?php
./
configure --prefix=/usr/local/nginx

配置文件

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
编译参数

<?php
./
configure --prefix=/usr/local/lighthttpd

配置文件

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
编译参数

<?php
./
configure --prefix=/usr/local/apache1.3.41

配置文件

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
编译参数

<?php
./
configure --prefix=/usr/local/apache2.2.8

配置文件

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并发

<?php
./
http_load -parallel 200 -fetches 1000 urls
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并发

<?php
./
http_load -parallel 500 -fetches 1000 urls
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并发

<?php
./
http_load -parallel 1000 -fetches 1000 urls
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并发

<?php
./
http_load -parallel 200 -fetches 1000 urls
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并发

<?php
./
http_load -parallel 500 -fetches 1000 urls
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并发

<?php
./
http_load -parallel 1000 -fetches 1000 urls
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并发

<?php
./
http_load -parallel 200 -fetches 1000 urls
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