存档

‘Apache’ 分类的存档

快递搭建企业级邮件系统iRedMail+Mysql+Postfix+php

2009年9月2日 Michael Field 4 条评论

一 软件环境
最近负责一个公司网站和邮件系统的搭建,以前自己一直没有仔细的研究过邮件系统的从零开始搭建工作,趁现在工作之余也同时将文档整理一次;
主要针对快捷高效搭建,简单实用为主,基本够一个人数50-100的小型公司使用。

操作系统:CentOS release 5.3 (Final) x86_64
数据库:mysql Ver 14.12 Distrib 5.0.45
php:php 5.2 up
邮件系统:postfix 2.5.6 + iredmail 0.4.0
webmail:RoundCube 1.0.2

iRedMail 0.4.0 下载地址:戳这里

二 安装过程
因许多软件涉及到yum安装,这里我给出国内一个非常快的Centos镜像,请戳这里下载
1. 数据库和邮件系统安装
mysql 安装和postfix 安装 全部采取yum安装

———————————————-
$ yum install -y mysql mysql-server mysql-devel
$ yum install -y postfix

2.php安装

———————————————-
$ yum install -y php php-ldap php-gd php-imap php-mysql php-pear php-mbstring

3.iredmail 安装
下载解压 iRedMail-0.4.0.tar.bz2
安装指令:

———————————————-
$ cd /path/to/iRedMail-x.y.z/
$ cd pkgs/
$ sh get_all.sh
$ cd ../
$ sh iRedMail.sh

安装过程详细介绍请参看:戳这里
注:
a:安装之前请先行设定mysql的root帐号和密码;空密码不被接受;
b:其中数据库只需选择mysql即可;
c:webprogrem选择RoundCube即可,其他默认;
d:请记住设定的mail admin的帐号和密码。

三 配置过程
因为iRedMail的高度整合,使得配置过程异常的简单。甚至可以不需要对postfix进行多余设定;
注意修改以下基本配置:iRedmail安装过程中已经增加的这部分设定,请在配置文件的最末尾处修改

1. myorigin
myorigin参数指明发件人所在的域名。如果你的用户的邮件地址为user@domain.com,则该参数指定@后面的域名。缺省地,postfix使用本地主机名作为myorigin,但是建议你最好使用你的域名,因为这样更具有可读性。比如:安装postfix的主机为 mail.domain.com则我们可以这样指定myorigin:

myorigin = domain.com
当然我们也可以引用其他参数,如:
myorigin = $mydomain

2. mydestination
mydestination参数指定postfix接收邮件时收件人的域名,换句话说,也就
是你的postfix系统要接收什么样的邮件。比如:你的用户的邮件地址为user@domain.com, 也就是你的域为domain.com, 则你就需要接收所有收件人为user_name@domain.com的邮件。与myorigin一样,缺省地,postfix使用本地主机名作为 mydestination。如:

mydestination = $mydomain
mydestination = domain.com

3. notify_classes
在postfix系统中,必须指定一个postfix系统管理员的别名指向一个用户,
只有这样,在用户遇到问题时才有报告的对象,postfix也才能将系统的问题报告给管理员。notify_classes参数就是用来指定向postfix管理员报告错误时的信息级别。共有以下几种级别:

bounce:将不可以投递的邮件的拷贝发送给postfix管理员。出于个人隐私的缘故,该邮件的拷贝不包含信头。

2bounce:将两次不可投递的邮件拷贝发送给postfix管理员。

delay:将邮件的投递延迟信息发送给管理员,仅仅包含信头。

policy:将由于UCE规则限制而被拒绝的用户请求发送给postfix管理员,包含整个SMTP会话的内容。

protocol:将协议的错误信息或用户企图执行不支持的命令的记录发送给postfix管理员。同样包含整个SMTP会话的内容。

resource:将由于资源错误而不可投递的错误信息发送给postfix管理员,比如:队列文件写错误等等。

software:将由于软件错误而导致不可投递的错误信息发送给postfix管理员。

缺省值为:

notify_classes = resource, software

4.myhostname
myhostname 参数指定运行postfix邮件系统的主机的主机名。缺省地,该值被设定为本地机器名。你也可以指定该值,需要注意的是,要指定完整的主机名。如:

myhostname = mail.domain.com

5.mydomain
mydomain参数指定你的域名,缺省地,postfix将myhostname的第一部分删除而作为mydomain的值。你也可以自己指定该值,如:

mydomain = domain.com

6.mynetworks
mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问。你可以用标准的A、B、C类网络地址,也可以用CIDR(无类域间路由)地址来表示,如:

192.168.1.0/24
192.168.1.0/26

7.inet_interfaces
inet_interfaces 参数指定postfix系统监听的网络接口。缺省地,postfix监听
所有的网络接口。如果你的postfix运行在一个虚拟的ip地址上,则必须指定其监听的地址。如:

inet_interfaces = all
inet_interface = 192.168.1.1

关于postfix的配置详细介绍可参看戳这里
需要注意的是dovecat配置在main.cf中的和master.cf的端口一致;否则会导致邮件发送失败;

———————————————-
#main.cf
content_filter = smtp-amavis:[127.0.0.1]:10024
#master.cf
127.0.0.1:10024 inet n – – – – smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_delay_reject=no
-o smtpd_client_restrictions=permit_mynetworks,reject
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks_style=host
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
-o smtpd_client_connection_count_limit=0
-o smtpd_client_connection_rate_limit=0
-o receive_override_options=no_header_body_checks,no_unknown_recipient_checks

以上设定完成后,确认启动postfix、policyd、dovecot、httpd、mysqld;

四、测试过程
1. 访问:http://your_server/mail/
webmail
以上设定正确,请登录测试发送邮件是否正常;

2. 增加邮件用户和邮箱容量大小配额设定
a.首先登录mysql;
b.依次执行以下指令:

———————————————-
mysql> use vmail;
Database changed
mysql> INSERT INTO mailbox (username, password, name, maildir, quota, domain, active)
-> VALUES (‘testuser@hiadmin.com’, ‘$1$W.UWoG.0$Bnq8mcbsi1UhFVpiJ2jvY0′, ‘testuser’, ‘hiamdin.com/testuser/’, ’2048′, ‘hiadmin.com’, ’1′);
Query OK, 1 row affected (0.00 sec)
注:
#在mailbox生成用户帐号、密码、以及邮箱容量quota 2048为2GB
#其中password字段值,可以使用 openssl passwd -1 testuser生成;

mysql> INSERT INTO alias (address, goto, domain, active)
-> VALUES (‘testuser@hiadmin.com’, ‘testuser@hiadmin.com’, ‘hiadmin.com’, ’1′);
Query OK, 1 row affected (0.00 sec)
注:
#alias 中生成别名;

c.也可以用iRedmail的tools 脚本;

———————————————-
$cd /path/to/iRedMail-0.4.0/tools #该目录下有个create_mail_user_MySQL.sh的脚本,可以为你生成增加用户的sql语句;
#执行脚本前实现生成userlist.txt
$echo testuser >userlist.txt #每行一个用户名即可
$sh create_mail_user_MySQL.sh userlist.txt #生成output.sql
#登录到mysql,在vmail库中执行
mysql> source /path/to/output.sql

d.设定自己域名的mx记录,再登录RoundCube测试能否收发邮件!

Apache 防盗链

2008年9月12日 ready 1 条评论

临时要求在apache中加防盗链。网上搜集了一些资料整理一下发在这里,方便以后翻阅。
关于mod_authz_host模块参看:http://doc.linuxpk.com/doc/apache/mod/mod_authz_host.html
1。通过User-Agent浏览器类型限制

下载: code.txt
SetEnvIf User-Agent ^blueapple go_out
<
directory /home/domain>
Order Allow,Deny
Allow  from all
Deny from env=go_out
</
directory>

2。通过Referer限制

下载: code.txt
SetEnvIf Referfer ^$ go_out
SetEnvIf Referfer ^http:\/\/baidu.com(\/|$)”  go_out
<
directory /home/domain>
Order Allow,Deny
Allow  from all
Deny from env=go_out
</
directory>

referer为空禁止访问。
referer为http://baidu.com限制访问。

分类: Apache 标签:

负载均衡环境中和如何设置Expires和Etag

2008年8月8日 Martin Guo 3 条评论

在负载均衡环境中(LVS, LoadBalance)为了减少浏览器数据的重复请求操作,一般需要设置 Http Header 的 Etage 和 Expires 告诉浏览器请求数据是否已过期。以下内容主要考虑Apache+squid 环境

ETag Header是文件修改时间、文件大小和inode号生成的校验(checksum),在多台服务器的负载均衡环境下会因部署内容的inode节点差异造成 ETag 的不同,在多台WEB前端做负载均衡的情况下,会因为请求同一个数据但不同机器的 ETag 而影响了响应. 具体表现为用户在第一次请求某一内容时下载而再次时浏览器会发现ETag不同而再次请求下载.。(再次刷新时查看是否响应码为:304)
对于Apache 可以使用 FileEtag 选项配置
Apache 的默认ETag的值总是由文件的索引节点(Inode)、大小(Size)、最后修改时间(MTime)决定
这里我们只需要去掉Inode即可
FileETag MTime Size
具体关于 FileETag 详细内容可以查看Apache官方文档

Expires用于控制请求文件的有效时间,当请求数据在有效期内时客户端浏览器从缓存请求数据而不是服务器端. 当缓存中数据失效或过期,才决定从服务器更新数据。
可以使用Apache的mod_expires 模块来设置,这包括控制应答时的Expires头内容和Cache-Control头的max-age指令

下载: code.txt
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/html "access plus 30 minutes"
ExpiresByType text/css  "access plus 30 minutes"
ExpiresByType text/js   "access plus 30 minutes"
ExpiresByType application/x-javascript   "access plus 30 minutes"
ExpiresByType application/x-shockwave-flash     "access plus 30 minutes"

以上设置为 图片文件的有效期为从请求文件开始1个月,html,css,js,flash文件的有效期为从请求文件开始30分钟
这里只是一个常规设置,Apache官方文档 对此设置有详细介绍
当设置了expires后,会自动输出Cache-Control 的max-age 信息,这个数值是expires有效期内的秒数,(一个月的数值为2592000) 在这个时间段里,该文件的请求都将直接通过缓存服务器获取,当然如果需要忽略浏览器的刷新请求(F5),缓存服务器squid还需要使用refresh_pattern 选项来忽略该请求

下载: code.txt
refresh_pattern -i .jpg  1440 50% 10080 reload-into-ims ignore-reload ignore-no-cache ignore-private

以下为实际输出的HTTP Header信息

下载: code.txt
Date    Thu, 07 Aug 2008 07:27:57 GMT
Server    Apache
Last-Modified    Fri, 27 Jun 2008 07:18:52 GMT
Etag    "df6-b8c8cf00"
Accept-Ranges    bytes
Content-Length    3574
Cache-Control    max-age=2592000
Expires    Sat, 06 Sep 2008 07:27:57 GMT
Content-Type    image/jpeg
Age    34241
X-Cache    HIT from s1.ihompy.com
Connection    keep-alive

对于动态页面的缓存如果不是频繁更新的页面数据,可以在squid缓存,只需要注意两点
1. session : 对于需要缓存的数据,一定要关闭session防止在http header 中包括session id 字段
2. Last-Modified 和 Expires 标记: 一般般纯静态页面本身都会有Last-Modified信息,这是由WEB服务器获取文件的最后修改时间生成的,而动态页面需要默认的输出内容是

下载: code.txt
Date    Thu, 07 Aug 2008 16:58:37 GMT
Expires    Thu, 19 Nov 1981 08:52:00 GMT
Last-Modified    Thu, 07 Aug 2008 16:58:37 GMT

这里的 Last-Modified 时间和请求文件的时间相同,也就是说该文件总是声明为最新的
在程序中需要输出Last-Modifed 和 Expires信息,比如php

下载: code.txt
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
header('Expires: ' . gmdate ("D, d M Y H:i:s", time() + 3600*24). " GMT");

以上信息设置php文件的过期时间为请求该文件的时间后的24小时(3600*24)


补充 ,以下内容来自 : 扶凯的blog
http://www.php-oa.com/2008/09/05/squidmaxageexpires.html


Squid和Apache中的max-age与Expires的分别

主要重点在于我们要明白一个相对(Expires)一个绝对(max-age).

分别

max-age
max-age是HTTP/1.1中,他是指我们的web中的文件被用户访问(请求)后的存活时间,是个相对的值,相对Request_time(请求时间).
例如:A.html 用户请求时间是18:00,max-age设置的是600的话,相当18:00+600秒过期,也就是相对18:00的时间后面600秒后过期.默认的max-age是由Expires算出来的.

Expires
Expires是HTTP/1.0中的,它比max-age要麻烦点.Expires指定的时间分下面二种,这个主要考虑到apache中设置是A还是M.

1.相对文件的最后访问时间(Atime)
当Apache使用A时间来做Expires时.这样设置时.他就和max-age的值相等,因为max-age是相对文件的请求时间(Atime).

例如:ExpiresByType text/html A600

由上面我们得知,Apache设置Atime时,过期为600秒时.
Expires=18:00+600=18:10
max-age=18:00+600=18:10
得出:Expires=max-age

2.绝对修改时间(MTime)
这又分二种情况,我们来拿A.htm来讲
假设文件的建立时间为18:00.

当用户Request请求为18:00时,过期为600秒
Expires=18:00+600=18:10
max-age=18:00+600=18:10
得出:Expires等于max-age

当用户Request请求为18:20时,过期为600秒

Expires=18:00+600=18:10(因为设置成Mtime时,时间由文件建立时间来决定)
max-age=18:20+600=18:30
得出:Expires不等于max-age

另外要注意,象上面这种清况时,max-age优化,所以过期时间为18:30.

在squid,如果没有指明expires和max-age这二个的截止时间,那它就会使用发式截止时间,如参考 Last-Modified.
其实上面的max-age=18:20+600=18:30,这样算max-age不对,真实环境要这样算,max-age过期为http头中的Age=600过期.
注:Age域值是缓存服务器估计从响应产生或被原始服务器重新证实以来的总时间.age的值是缓存服务器算出来的,原始服务器是没有的.

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月28日 Johnny Woo 没有评论

网上针对HTTPD的性能一直有着流言性质的定论
认为apache一定是最弱的
而且许多测试也这样表明

很多人常常引用的测试结果
源于
http://www.litespeedtech.com/products/webserver/benchmark/
而其中第二个测试的结果
与最新第三次测试的结果
apache的表现有明显差异
在详细检查文档后发现
较早的一次比对中,服务器的内存只有256MB,使用单核XEON
而较近的一次比对,服务器的内存升级至1G,而且使用双核XEON
这种条件下
apache的性能极升,与lighthttpd有着相似的性能,
并且在某些条件下还超过了lighthttpd
即便在Small Static File (Non-Keepalive)的测试中
apache与lighthttpd的差异也并不明显
所以在内存较低的情况下
使用lighthttpd等轻量服务器会比较好
而当CPU和内存比较大的情况下
APACHE的性能则未必如流言一般不堪.

分类: Apache 标签:

HTTP传输压缩gzip比较

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

分类: Apache 标签:

Apache启用gzip压缩

2008年4月25日 Johnny Woo 没有评论
下载: code.txt
  1. <ifmodule mod_deflate.c>
  2. DeflateCompressionLevel 6
  3. SetOutputFilter DEFLATE
  4. DeflateFilterNote Input instream
  5. DeflateFilterNote Output outstream
  6. DeflateFilterNote Ratio ratio
  7. LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
  8. CustomLog logs/deflate_log.log deflate
  9. </ifmodule>

压缩率6以上
则压缩效果不明显
并且CPU占用率提高过多

分类: Apache 标签:

轻量级HTTP服务程序比较

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

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

分类: Apache, LightHttpd, Nginx 标签: