我们可以给一个网站配置静态缓存,缓存一些图片或文字之类的,这样用户再次访问我们网站的时候就不用再加载图片或文字了,因为已经缓存在客户端了,可以节省我们的带宽,同时提高访问速度,Apache 配置静态缓存通过添加 expires 模块来实现
[root@localhost ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/data/www"
ServerName www.test.com
ErrorLog "logs/test.com_error_log"
CustomLog "logs/test.com_access_log" combined
<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 text/css "now plus 2 hour"
ExpiresByType application/x-javascript "now plus 2 hours"
ExpiresByType application/javascript "now plus 2 hours"
ExpiresByType application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
</IfModule>
</VirtualHost>
[root@localhost ~]# /usr/local/apache2/bin/apachectl -t
[root@localhost ~]# /usr/local/apache2/bin/apachectl graceful