<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OurApache &#187; mod_headers</title>
	<atom:link href="http://ourapache.com/archives/tag/mod_headers/feed" rel="self" type="application/rss+xml" />
	<link>http://ourapache.com</link>
	<description>我们致力于一个Apache知识的分享网站</description>
	<lastBuildDate>Tue, 13 Apr 2010 05:18:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>使用mod_headers或mod_expires落实缓存</title>
		<link>http://ourapache.com/archives/203</link>
		<comments>http://ourapache.com/archives/203#comments</comments>
		<pubDate>Fri, 27 Feb 2009 03:25:54 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache初级应用]]></category>
		<category><![CDATA[mod_expires]]></category>
		<category><![CDATA[mod_headers]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=203</guid>
		<description><![CDATA[实施这一方法将节省你难以置信数额的带宽，极大地加快你的网站为你的网站访客。基本上，对于图片，CSS ， JavaScript以及其他文件可以通过优化更快的下载，告诉你的网站访问者快取记忆体，为他们在某一段时间内。默认的行为是每一次请求检查文件的last-modified 和/或者  Etag headers。

所以一个用户去/home/index.html，及浏览器缓存所有图象和文件。然后用户离开网站稍后回来，与浏览器发送If-Modified-Since 有条件的GET 请求为每一个缓存的项目时，基本上看，如果文件已被改变和他们必须更新他们的缓存。

当你执行在这篇文章中所述的缓存方法，你可以指定某文件或扩展名被缓存为某一特定数额的时间。这些文件然后缓存在你的网站访客和他们不发送If-Modified-Since头直到设置的缓存时间已经到了。]]></description>
			<content:encoded><![CDATA[<p>     实施这一方法将节省你难以置信数额的带宽，极大地加快你的网站为你的网站访客。基本上，对于图片，CSS ， JavaScript以及其他文件可以通过优化更快的下载，告诉你的网站访问者快取记忆体，为他们在某一段时间内。默认的行为是每一次请求检查文件的last-modified 和/或者  Etag headers。</p>
<p>    所以一个用户去/home/index.html，及浏览器缓存所有图象和文件。然后用户离开网站稍后回来，与浏览器发送If-Modified-Since 有条件的GET 请求为每一个缓存的项目时，基本上看，如果文件已被改变和他们必须更新他们的缓存。</p>
<p>    当你执行在这篇文章中所述的缓存方法，你可以指定某文件或扩展名被缓存为某一特定数额的时间。这些文件然后缓存在你的网站访客和他们不发送If-Modified-Since头直到设置的缓存时间已经到了。</p>
<blockquote><p>#================================================= ============================#<br />
# TIME CHEAT SHEET<br />
#================================================= ============================#<br />
# 300 5 M # 604800 1 W<br />
# 2700 45 M # 1814400 3 W<br />
# 3600 1 H # 2419200 1 M<br />
# 54000 15 H # 14515200 6 M<br />
# 86400 1 D # 26611200 11 M<br />
# 518400 6 D # 29030400 1 Y (never expire)</p></blockquote>
<p>    第一个解决办法是Apache模块mod_expires <a href="http://httpd.apache.org/docs/1.3/mod/mod_expires.html"><span style="color: #3388cc;">1.3</span></a> <a href="http://httpd.apache.org/docs/2.0/mod/mod_expires.html"><span style="color: #3388cc;">2.0</span></a> <a href="http://httpd.apache.org/docs/2.0/mod/mod_expires.html"><span style="color: #3388cc;">2.2</span></a></p>
<blockquote><p>ExpiresActive On<br />
ExpiresDefault A300<br />
ExpiresByType image/x-icon A2592000<br />
ExpiresByType application/x-javascript A2592000<br />
ExpiresByType text/css A2592000<br />
ExpiresByType image/gif A604800<br />
ExpiresByType image/png A604800<br />
ExpiresByType image/jpeg A604800<br />
ExpiresByType text/plain A604800<br />
ExpiresByType application/x-shockwave-flash A604800<br />
ExpiresByType video/x-flv A604800<br />
ExpiresByType application/pdf A604800<br />
ExpiresByType text/html A300</p></blockquote>
<p>    第二个解决办法是mod_headers <a href="http://httpd.apache.org/docs/1.3/mod/mod_headers.html"><span style="color: #3388cc;">1.3</span></a> <a href="http://httpd.apache.org/docs/2.0/mod/mod_headers.html"><span style="color: #3388cc;">2.0</span></a> <a href="http://httpd.apache.org/docs/2.2/mod/mod_headers.html"><span style="color: #3388cc;">2.2</span></a></p>
<blockquote><p> # YEAR<br />
&lt;FilesMatch “\.(flv|gif|ico)$”&gt;<br />
Header set Cache-Control “max-age=2592000″<br />
&lt;/FilesMatch&gt;</p>
<p># WEEK<br />
&lt;FilesMatch “\.(pdf|swf|js|css)$”&gt;<br />
Header set Cache-Control “max-age=604800″<br />
&lt;/FilesMatch&gt;</p>
<p># NEVER CACHE<br />
&lt;FilesMatch “\.(html|cgi|php|htm)$”&gt;<br />
Header set Expires “Thu, 01 Dec 2003 16:00:00 GMT”<br />
Header set Cache-Control “no-store, no-cache, must-revalidate”<br />
Header set Pragma “no-cache”<br />
&lt;/FilesMatch&gt;</p></blockquote>
<p id="result_box" dir="ltr">    注：<a href="http://www.askapache.com/htaccess/using-filesmatch-and-files-in-htaccess.html"><span style="color: #3388cc;">用filesmatch和files在htaccess文件</span></a></p>
<p dir="ltr">    这里是Headers当下载一个JPEG图像的时候，</p>
<p id="result_box" dir="ltr">    这个缓存方案实施后和没有缓存时的效果。</p>
<p dir="ltr">    JPEG 没有缓存的时</p>
<blockquote>
<p dir="ltr">Last-Modified: Wed, 22 Feb 2006 12:16:56 GMT<br />
ETag: “b57d54-45e7″<br />
Accept-Ranges: bytes<br />
Content-Length: 17895<br />
Connection: close<br />
Content-Type: image/jpeg</p>
</blockquote>
<p dir="ltr">    缓存过的</p>
<blockquote>
<p dir="ltr">Cache-Control: max-age=2592000<br />
Expires: Tue, 28 Mar 2006 16:23:52 GMT<br />
Last-Modified: Wed, 22 Feb 2006 12:16:56 GMT<br />
ETag: “b57d54″<br />
Accept-Ranges: bytes<br />
Content-Length: 17895<br />
Connection: close<br />
Content-Type: image/jpeg<br />
Content-Language: en</p>
</blockquote>
<p id="result_box" dir="ltr">附：</p>
<p dir="ltr">apache配置文件例子：</p>
<blockquote>
<p dir="ltr">example 1</p>
<p dir="ltr"># htm files are php<br />
AddHandler application/x-httpd-php .php .htm</p>
<p># setup errordocuments to local php file<br />
ErrorDocument 404 /cgi-bin/error.htm<br />
ErrorDocument 403 /cgi-bin/error.htm<br />
ErrorDocument 500 /cgi-bin/error.htm</p>
<p># Turn on Expires and set default expires to 3 days<br />
ExpiresActive On<br />
ExpiresDefault A259200</p>
<p># Set up caching on media files for 1 month<br />
&lt;FilesMatch “\.(ico|gif|jpg|jpeg|png|flv|pdf|swf|mov|mp3|wmv|pp t)$”&gt;<br />
ExpiresDefault A2419200<br />
Header append Cache-Control “public”<br />
&lt;/FilesMatch&gt;</p>
<p># Set up 2 Hour caching on commonly updated files<br />
&lt;FilesMatch “\.(xml|txt|html|js|css)$”&gt;<br />
ExpiresDefault A7200<br />
Header append Cache-Control “private, must-revalidate”<br />
&lt;/FilesMatch&gt;</p>
<p># Force no caching for dynamic files<br />
&lt;FilesMatch “\.(php|cgi|pl|htm)$”&gt;<br />
ExpiresDefault A0<br />
Header set Cache-Control “no-store, no-cache, must-revalidate, max-age=0″<br />
Header set Pragma “no-cache”<br />
&lt;/FilesMatch&gt;</p>
</blockquote>
<p dir="ltr">example 2</p>
<blockquote>
<p dir="ltr"># htm files are php<br />
AddHandler application/x-httpd-php .php .htm</p>
<p># setup errordocuments to local php file<br />
ErrorDocument 404 /cgi-bin/error.htm<br />
ErrorDocument 403 /cgi-bin/error.htm<br />
ErrorDocument 500 /cgi-bin/error.htm</p>
<p># Turn on Expires and set default to 0<br />
ExpiresActive On<br />
ExpiresDefault A0</p>
<p># Set up caching on media files for 1 year (forever?)<br />
&lt;FilesMatch “\.(ico|flv|pdf|mov|mp3|wmv|ppt)$”&gt;<br />
ExpiresDefault A29030400<br />
Header append Cache-Control “public”<br />
&lt;/FilesMatch&gt;</p>
<p># Set up caching on media files for 1 week<br />
&lt;FilesMatch “\.(gif|jpg|jpeg|png|swf)$”&gt;<br />
ExpiresDefault A604800<br />
Header append Cache-Control “public, proxy-revalidate”<br />
&lt;/FilesMatch&gt;</p>
<p># Set up 2 Hour caching on commonly updated files<br />
&lt;FilesMatch “\.(xml|txt|html|js|css)$”&gt;<br />
ExpiresDefault A7200<br />
Header append Cache-Control “private, proxy-revalidate, must-revalidate”<br />
&lt;/FilesMatch&gt;</p>
<p># Force no caching for dynamic files<br />
&lt;FilesMatch “\.(php|cgi|pl|htm)$”&gt;<br />
ExpiresDefault A0<br />
Header set Cache-Control “no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform”<br />
Header set Pragma “no-cache”<br />
&lt;/FilesMatch&gt;</p>
</blockquote>
<p>-end-</p>
<p> 原始文章: Speed Up Sites with htaccess Caching (<a href="http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html"><span style="color: #009de5;">http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html</span></a><a href="http://www.askapache.com/2006/htaccess/speed-up-sites-with-htaccess-caching.html"></a>)</p>
<p> 翻译：<a href="http://www.pcstar.net.ru/"><span style="color: #3388cc;">XINGXING</span></a></p>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2009年03月9号 -- <a href="http://ourapache.com/archives/227" title="通过SNMP协议来监视Apache服务器">通过SNMP协议来监视Apache服务器</a></li><li>2009年02月7号 -- <a href="http://ourapache.com/archives/97" title="使用apache下的301设置来做域名的更换转移">使用apache下的301设置来做域名的更换转移</a></li><li>2010年03月9号 -- <a href="http://ourapache.com/archives/318" title="Apache2中俩种设置PHP的异同">Apache2中俩种设置PHP的异同</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/104" title="Apache和IIS共享80端口的四个方法">Apache和IIS共享80端口的四个方法</a></li><li>2009年02月6号 -- <a href="http://ourapache.com/archives/72" title="gzip 与 deflate">gzip 与 deflate</a></li><li>2009年02月22号 -- <a href="http://ourapache.com/archives/161" title="在Windows上手动配置Apache下面的虚拟主机站点">在Windows上手动配置Apache下面的虚拟主机站点</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/234" title="Apache的prefork模式和worker模式">Apache的prefork模式和worker模式</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/25" title="Apache服务器使用.htaccess实现图片防盗链方法教程">Apache服务器使用.htaccess实现图片防盗链方法教程</a></li><li>2009年02月27号 -- <a href="http://ourapache.com/archives/193" title="header Content-Type类型">header Content-Type类型</a></li><li>2009年02月6号 -- <a href="http://ourapache.com/archives/76" title="Apache 模块说明">Apache 模块说明</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/primary" title="Apache初级应用" rel="tag">Apache初级应用</a>, <a href="http://ourapache.com/archives/tag/mod_expires" title="mod_expires" rel="tag">mod_expires</a>, <a href="http://ourapache.com/archives/tag/mod_headers" title="mod_headers" rel="tag">mod_headers</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/203/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

