<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[[个人原创]让nginx的proxy_store和proxy_cache支持ctrl+f5和PURGE二种方法]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Web服务器]]></category>
<pubDate>Mon, 11 Jul 2011 06:56:45 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	&nbsp;&nbsp; 主要是对我的个人博客的PHP执行代码进行Cache，对于Js，CSS直接在客户端缓存即可，这儿重点是对PHP的CGI执行结果在服务器端进行缓存，以减少服务器的DB查询压力，这样DB从21次/秒降低到13次/秒。目前让nginx的proxy_store和proxy_cache支持ctrl+f5和PURGE结合删除缓存的方法二种：<br/>一.让ngx_cache_purge来帮忙，通过Nginx对ctrl+f5的标志来进行重写清除日志。<br/>二.用PHP来实现清除后并再次跳转到对应的Uri模块,以实现页面缓存更新后的显示。<br/>三.修改ngx_cache_purge源代码。。。。：（暂时忽略。<br/>-----------------<br/>方法一：<br/><br/>步骤1：需要编译安装ngx_cache_purge这个模块让它来对缓存进行清理。<br/><textarea name="code" class="html" rows="15" cols="100">
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module&nbsp;&nbsp; --add-module=/root/software/nginx_http_push_module-0.692&nbsp;&nbsp; --add-module=/root/software/ngx_cache_purge-1.3
</textarea><br/><br/>步骤2：<br/>nginx.conf中加入对Ctrl+F5刷新的标志判断并UrlRewrite：<br/><textarea name="code" class="html" rows="15" cols="100">
 #limit_zone&nbsp;&nbsp;crawler&nbsp;&nbsp;$binary_remote_addr&nbsp;&nbsp;10m;
fastcgi_cache_path /data0/proxy_temp_dir&nbsp;&nbsp;levels=1:2&nbsp;&nbsp;keys_zone=cache_php:30m inactive=1d max_size=1g;
fastcgi_temp_path /data0/ngx_fcgi_tmp;
location ~ /purge(/.*)
&#123;
&nbsp;&nbsp;fastcgi_cache_purge cache_php $host$1$is_args$args;
&#125;
if ( $request_method = &quot;PURGE&quot; ) &#123;
rewrite ^(.*)$ /purge$1 last;
&#125;

#limit_conn&nbsp;&nbsp; crawler&nbsp;&nbsp;20;&nbsp;&nbsp;&nbsp;&nbsp;
location ~ .*&#92;.(php&#124;php5)?$
&#123;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;#fastcgi_pass&nbsp;&nbsp;unix:/tmp/php-cgi.sock;
&nbsp;&nbsp;fastcgi_pass&nbsp;&nbsp;127.0.0.1:9000;
&nbsp;&nbsp;fastcgi_index index.php;
&nbsp;&nbsp;include fcgi.conf;
&nbsp;&nbsp;#以下是fastcgi_cache的配置
&nbsp;&nbsp;fastcgi_cache&nbsp;&nbsp; cache_php;
&nbsp;&nbsp;fastcgi_cache_valid&nbsp;&nbsp; 200 302&nbsp;&nbsp;1h;
&nbsp;&nbsp;fastcgi_cache_min_uses&nbsp;&nbsp;1;
&nbsp;&nbsp;fastcgi_cache_use_stale error&nbsp;&nbsp;timeout invalid_header http_500;
&nbsp;&nbsp;#fastcgi_cache_key http://$host$request_uri;
&nbsp;&nbsp;fastcgi_cache_key $host$uri$is_args$args;
&nbsp;&nbsp;if ($http_Cache_Control ~ &quot;no-cache&quot;) 
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;set $http_Cache_Control &#039;max-age=604800&#039;;
&nbsp;&nbsp;&nbsp;&nbsp;rewrite ^(.*)$ /purge$1 last;
&nbsp;&nbsp;&#125;
&#125;
</textarea><br/><br/>对已经缓存的页面用Ctrl+F5后出现：<br/>Successful purge<br/><br/>Key : jackxiang.com/read.php?entryid=4454&amp;page=&amp;part=<br/>Path: /data0/proxy_temp_dir/c/b8/ea9939947c0cf37b9cae885987876b8c<br/>nginx/1.0.4<br/><br/>清理成功！！<br/>-----------------<br/>方法二：<br/>步骤1：<br/>用PHP来实现，其Nginx配置代码修改为：<br/><textarea name="code" class="html" rows="15" cols="100">
 #limit_zone&nbsp;&nbsp;crawler&nbsp;&nbsp;$binary_remote_addr&nbsp;&nbsp;10m;
fastcgi_cache_path /data0/proxy_temp_dir&nbsp;&nbsp;levels=1:2&nbsp;&nbsp;keys_zone=cache_php:30m inactive=1d max_size=1g;
fastcgi_temp_path /data0/ngx_fcgi_tmp;
location ~ /purge(/.*)
&#123;
&nbsp;&nbsp;fastcgi_pass&nbsp;&nbsp; 127.0.0.1:9000;
&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fastcgi_params;
&nbsp;&nbsp;fastcgi_param&nbsp;&nbsp;SCRIPT_FILENAME&nbsp;&nbsp;&nbsp;&nbsp;/data0/htdocs/blog/purge.php;
&nbsp;&nbsp;error_page 405 =200 /purge$1;
&#125;
if ( $request_method = &quot;PURGE&quot; ) &#123;
rewrite ^(.*)$ /purge$1 last;
&#125;
#limit_conn&nbsp;&nbsp; crawler&nbsp;&nbsp;20;&nbsp;&nbsp;&nbsp;&nbsp;
location ~ .*&#92;.(php&#124;php5)?$
&#123;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;#fastcgi_pass&nbsp;&nbsp;unix:/tmp/php-cgi.sock;
&nbsp;&nbsp;fastcgi_pass&nbsp;&nbsp;127.0.0.1:9000;
&nbsp;&nbsp;fastcgi_index index.php;
&nbsp;&nbsp;include fcgi.conf;
&nbsp;&nbsp;#以下是fastcgi_cache的配置
&nbsp;&nbsp;fastcgi_cache&nbsp;&nbsp; cache_php;
&nbsp;&nbsp;fastcgi_cache_valid&nbsp;&nbsp; 200 302&nbsp;&nbsp;1h;
&nbsp;&nbsp;fastcgi_cache_min_uses&nbsp;&nbsp;1;
&nbsp;&nbsp;fastcgi_cache_use_stale error&nbsp;&nbsp;timeout invalid_header http_500;
&nbsp;&nbsp;#fastcgi_cache_key http://$host$request_uri;
&nbsp;&nbsp;fastcgi_cache_key $host$uri$is_args$args;
&nbsp;&nbsp;if ($http_Cache_Control ~ &quot;no-cache&quot;) 
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;set $http_Cache_Control &#039;max-age=604800&#039;;
&nbsp;&nbsp;&nbsp;&nbsp;rewrite ^(.*)$ /purge$1 last;
&nbsp;&nbsp;&#125;
&#125;
</textarea><br/>步骤2：<br/>通过UrlRewrite后的结果到purge.php后进行Md5目录规则的删除，并再次刷新该页面，<br/>purge.php代码如下：<br/><textarea name="code" class="html" rows="15" cols="100">
&lt;?php
@header(&quot;Content-Type: text/html; charset=utf-8&quot;);
@header(&quot;Expires: Mon, 26 Jul 1997 05:00:00 GMT&quot;);
@header(&quot;Last-Modified: &quot; . gmdate(&quot;D, d M Y H:i:s&quot;) . &quot; GMT&quot;);
@header(&quot;Cache-Control: no-store, no-cache, must-revalidate&quot;);
@header(&quot;Pragma: no-cache&quot;);
$host = isset($_SERVER[&#039;HTTP_X_FORWARDED_HOST&#039;]) ? $_SERVER[&#039;HTTP_X_FORWARDED_HOST&#039;] : (isset($_SERVER[&#039;HTTP_HOST&#039;]) ? $_SERVER[&#039;HTTP_HOST&#039;] : &#039;&#039;);
//uri
function request_uri()
&#123;
&nbsp;&nbsp;if (isset($_SERVER[&#039;REQUEST_URI&#039;]))
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$uri = $_SERVER[&#039;REQUEST_URI&#039;];
&nbsp;&nbsp;&#125;
&nbsp;&nbsp;else
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;if (isset($_SERVER[&#039;argv&#039;]))
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$uri = $_SERVER[&#039;PHP_SELF&#039;] .&#039;?&#039;. $_SERVER[&#039;argv&#039;][0];
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$uri = $_SERVER[&#039;PHP_SELF&#039;] .&#039;?&#039;. $_SERVER[&#039;QUERY_STRING&#039;];
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&#125;
&nbsp;&nbsp;return $uri;
&#125;
$uri = request_uri();

$url = &quot;http://&quot;.$host.$uri;
$md5 = md5($url);
$cacheRoot = &quot;/data0/proxy_temp_dir&quot;;
$cacheFile = $cacheRoot . &#039;/&#039; . substr($md5, -1, 1) . &#039;/&#039; . substr($md5, -3, 2) . &#039;/&#039; . $md5;
if(is_file($cacheFile))
&#123;
&nbsp;&nbsp;@unlink($cacheFile);
&#125;
echo &#039;&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;&#039;;
echo &quot;window.location.href=&#039;&#123;$url&#125;&#039;&quot;;
echo &#039;&lt;/script&gt;&#039;;
?&gt;

</textarea><br/><br/><br/><br/><br/>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [个人原创]让nginx的proxy_store和proxy_cache支持ctrl+f5和PURGE二种方法]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>