Apache配置静态缓存

Apache配置静态缓存

[root@daixuan logs]# apachectl -M   Apache的静态缓存使用的是expires_module

expires_module (shared)        

[root@daixuan logs]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

<VirtualHost *:80> 在虚拟主机配置文件中添加红色的expires_module模块

<IfModule mod_expires.c>

     ExpiresActive on

     ExpiresByType image/gif "access plus 1 days"

     ExpiresByType image/jpeg "access plus 24 hours"

     ExpiresByType image/png "access plus 24 hours"

     ExpiresByType test/css "now plus 2 hours"

     ExpiresByType application/x-javascripts "now plus 2 hours"

     ExpiresByType application/x-shockwave-flash "now plus 2 hours"

     ExpiresDefault "now plus 0 min"

</IfModule>

<IfModule mod_rewrite.c>

内容省略。。。。

</IfModule>

</VirtualHost>


[root@daixuan logs]# apachectl -t

Syntax OK

[root@daixuan logs]# apachectl restart

[root@daixuan logs]# curl -x 192.168.101.230:80 'http://www.test.com/static/image/common/logo_88_31.gif' -I

HTTP/1.1 200 OK

Date: Tue, 01 Dec 2015 08:03:56 GMT

Server: Apache/2.2.31 (Unix) PHP/5.4.45

Last-Modified: Tue, 09 Jun 2015 02:21:10 GMT

ETag: "1dfab2-9e0-5180c695e1180"

Accept-Ranges: bytes

Content-Length: 2528

Cache-Control: max-age=86400    一天时间

Expires: Wed, 02 Dec 2015 08:03:56 GMT

Content-Type: image/gif


如果修改

ExpiresByType image/gif "access plus 2 days"

Cache-Control: max-age=172800   两天时间


注:now和access,hour和hours都一样用!


你可能感兴趣的:(Apache配置静态缓存)