Apache httpd 是个很好的web服务器选择,性能强大,扩展性强,合理配置好apache的模块(module)是非常重要的,直接影响到性能。最近在Unix上配置Apache时,琢磨出些东西,于是就写了下来:
如果是目前单单配一个提供静态服务的功能,且考虑到以后的功能扩展,安装编译时就用动态共享对象(DSO)模式,编译参数里带上自己需要额外添加的模块,后续需要扩展直接配置httpd.conf即可,方便易于维护。
若提供单一的静态服务,只需加载下面5个模块:
authz_host_module 供基于主机名、IP地址、请求特征的访问控制,最基本的。
logio_module 对每个请求的输入/输出字节数以及HTTP头进行日志记录,简单的日志,必备。
mime_module 通过读取部分文件内容自动猜测文件的MIME类型,不然就不能正确打开html文件,也不能正确显示图片,等等,但可以输出的。
dir_module 指定目录索引文件以及为目录提供"尾斜杠"重定向,这样方便使用。
speling_module 自动纠正URL中的拼写错误,也是容错,方便使用的。
如果再加上一个自动索引目录和文件的功能,在加上下面1个模块:
autoindex_module 自动对目录中的内容生成列表,类似于"ls"或"dir"命令。
为了安全,这个功能最好在特定的目录下使用,比如只在archive这个目录下使用:
首先去掉apache主目录的索引:
Options -indexes FollowSymLinks
然后添加下面的一个新的目录配置:
<Directory "/usr/home/holeo/webapps/ROOT/archive">
Options indexes
IndexOptions FancyIndexing NameWidth=60 FoldersFirst
ServerSignature on
</Directory>
为了提高传输效率,尚且还可增加一个Gzip功能,压缩输出的文件到客户端,减少传输时间和带宽,对静态文件如html,css,js很实用,可增加下面3个模块:
deflate_module 压缩发送给客户端的内容,这是主角。
headers_module 允许通过配置文件控制任意的HTTP请求和应答头信息,发送带gzip的消息。
setenvif_module 根据客户端请求头字段设置环境变量,浏览器类型比对(BrowserMatch),因为有些客户端浏览器不支持gzip,所以这个时候就不能压缩内容,否则客户端就不能正确显示内容;还有请求文件类型的比对,比如只压缩html,css,js,其他gif,jpg,zip等就不压缩,如果压缩图像以及zip等会增加服务器的额外负担,这样得不偿失。
使用gzip,还需配置下面的内容,这是本人使用的配置代码:
<Location />
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|bmp|ico|exe|bin|rar|zip|iso|7z|rpm|tar|gz|bz|bz2|mp3|wav|avi|mkv|mov|wmv|wma|swf|flv)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
这些就是最常用的模块配置了,当然更多的功能,更强劲的还在其他更多的模块中,才能体现出Apache httpd真正的伟大。哈哈~
Wednesday, April 01, 2009
关于Apache httpd模块的一点笔记
Comment (1)

Sort by: Date Rating Last Activity
Loading comments...
Thanks for sharing such a helpful, and understandable blog. I really enjoyed reading it.
Robots for kids
Robotic Online Classes
Robotics School Projects
Programming Courses Malaysia
Coding courses
Coding Academy
coding robots for kids
Coding classes for kids
Coding For Kids
Robots for kids
Robotic Online Classes
Robotics School Projects
Programming Courses Malaysia
Coding courses
Coding Academy
coding robots for kids
Coding classes for kids
Coding For Kids
Comments by IntenseDebate
Posting anonymously.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment