使用文本编辑器,打开 httpd.conf 文件。缺省情况下,此文件存储在以下目录中:
- Linux:/opt/IBM/HTTPServer/conf
-
AIX:/usr/IBM/HTTPServer/conf
- Microsoft Windows:C:\IBM\HTTPServer\conf
一、压缩设置
如果没有使用 IBM WebSphere Application Server Edge Components 或类似的设备压缩内容,那么请考虑配置 IBM HTTP Server 压缩特定类型的内容,以提高浏览器性能。
将伪指令添加到 httpd.conf 文件时,请务必按照在以上步骤中定义这些伪指令的相同顺序进行添加。
要指定压缩的文件类型,请完成下列步骤:
LoadModule headers_module modules/mod_headers.so
#Load 修改header的模块。
LoadModule expires_module modules/mod_expires.so
#Load 设定过期header的模块。
Header append Via: CCN-BJ-4-502
#增加一个Via header,值配置成设备的hostname。
KeepAliveTimeout 60
#设置连接的保持时间为60秒。
ExpiresActive On
#启用过期header功能。
ExpiresDefault A604800
#缺省过期时间为“访问后的604800秒”
#取消Etag,去掉Etag带来的干扰
FileETag none
<Directory /data/download/pplive/list.pplive.com/>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
ExpiresByType text/html A300
#text/html类型文件的过期设置为“访问后的300秒”
ExpiresByType text/css A259200
#text/css类型文件的过期设置为“访问后的259200秒”
ExpiresByType application/x-javascript A300
# application/x-javascript类型文件的过期设置为“访问后的300秒”
ExpiresByType image/gif A2592000
#image/gif类型文件的过期设置为“访问后的2592000秒”
ExpiresByType application/x-shockwave-flash A2592000
# application/x-shockwave-flash类型文件的过期设置为“访问后的2592000秒”
</Directory>
上述配置文件中load的两个模块:mod_headers.so 和mod_expires.so 可以让Apache具有对header的一些定制功能。
ExpiresByType: 表示按照文件类型-MIME-TYPE设定过期策略;
A300:表示在Access后300秒后过期;
ExpiresByType text/css A2592000: 表示Mime type是text/css的文件,在Access后2592000秒过期。
ExpiresDefault A604800: 表示除了单独制定的文件类型等过期策略外的其他内容,按照这个缺省的策略设定:访问后604800秒过期。
过期例子:
|
#加载expires模块 LoadModule expires_module modules/mod_expires.so #取消Etag,去掉Etag带来的干扰 FileETag none ExpiresActive On ExpiresDefault "access plus 10 years" ExpiresByType image/gif "access plus 10 years" ExpiresByType image/jpeg "access plus 10 years" ExpiresByType image/png "access plus 10 years" ExpiresByType text/css "access plus 10 years" ExpiresByType text/html "access plus 1 seconds" ExpiresByType text/javascript "access plus 10 years" ExpiresByType application/x-unknown-content-type "access plus 10 years" ExpiresByType application/x-javascript "access plus 10 years" |
设置过期也压缩之后,我进行了测试,None为没有进行压缩,pack是进行了合并(包括图片,脚本,和样式合并),Gzip则是开启了压缩,他们之间测试对比如下:


本文介绍如何通过配置HTTP服务器的httpd.conf文件来实现文件压缩及过期设置,以提升浏览器性能和缓存效率。
4511

被折叠的 条评论
为什么被折叠?



