wp-super-cache如何在Nginx下启用的mod_rewrite缓存模式及其配置规则
记录一下,如何在Nginx下启用mod_rewrite
location / {
<span class="hljs-comment"># 如果请求的文件已存在,直接返回</span>
<span class="hljs-keyword">if</span> (<span class="hljs-operator">-f</span> <span class="hljs-variable">$request_filename</span>) {
<span class="hljs-built_in">break</span>;
}
<span class="hljs-built_in">set</span> <span class="hljs-variable">$supercache_file</span> <span class="hljs-string">''</span>;
<span class="hljs-built_in">set</span> <span class="hljs-variable">$supercache_uri</span> <span class="hljs-variable">$request_uri</span>;
<span class="hljs-built_in">set</span> <span class="hljs-variable">$supercache</span> <spanclass="hljs-number">1</span>;
<span class="hljs-built_in">set</span> <span class="hljs-variable">$ihttp_host</span> <span class="hljs-string">''</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$request_method</span> =POST) {
<span class="hljs-built_in">set</span> <span class="hljs-variable">$supercache</span> <spanclass="hljs-number">0</span>;
}
<span class="hljs-comment"># 仅在访问文章永久链接时使用静态文件,请求中带参数则不使用静态缓存</span>
<span class="hljs-built_in">set</span> <span class="hljs-variable">$qs</span> <span class="hljs-number">0</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$query_string</span>) {
<span class="hljs-built_in">set</span> <span class="hljs-variable">$qs</span> <span class="hljs-number">1</span>;
}
<span class="hljs-comment"># 不过从 twitter, facebook, feedburner 链接点过来的,总是带参数,这些访问仍然可以使用静态文件</span>
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$query_string</span> ~* <span class="hljs-string">"^utm_source=([^&]+)&utm_medium([^&]+)&utm_campaign=([^&]+)(&utm_content=([^&]+))?$"</span>) {
<span class="hljs-built_in">set</span> <span class="hljs-variable">$qs</span> <span class="hljs-number">0</span>;
<span class="hljs-built_in">set</span> <span class="hljs-variable">$supercache_uri</span> <span class="hljs-variable">$document_uri</span>;
}
<span class="hljs-comment">#deactivate on high load</span>
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$qs</span> = <span class="hljs-number">1</span>) {
<span class="hljs-built_in">set</span> <span class="hljs-variable">$supercache</span> <spanclass="hljs-number">0</span>;
}
<span class="hljs-comment"># 针对已登录用户(发表过评论),可以不静态化。在访问量高峰时可注释掉</span>
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$http_cookie</span> ~* <span class="hljs-string">"comment_author_|wordpress|wp-postpass_"</span> ) {
<span class="hljs-built_in">set</span> <span class="hljs-variable">$supercache</span> <spanclass="hljs-number">0</span>;
}
<span class="hljs-comment"># 支持移动设备,访问移动版本的网页缓存</span>
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$http_user_agent</span> ~*<span class="hljs-string">'(iphone|ipod|aspen|incognito|webmate|android|dream|cupcake|froyo|blackberry9500|blackberry9520|blackberry9530|blackberry9550|blackberry 9800|webos|s8000|bada)'</span>) {
<span class="hljs-built_in">set</span> <span class="hljs-variable">$ihttp_host</span> <span class="hljs-string">'-mobile'</span>;
}
<span class="hljs-comment"># 指定静态缓存文件的路径</span>
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$supercache</span> = <span class="hljs-number">0</span>) {
<span class="hljs-built_in">set</span> <span class="hljs-variable">$supercache_uri</span> <span class="hljs-string">''</span>;
}
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$supercache_uri</span> ~ ^(.+)$) {
<span class="hljs-built_in">set</span> <span class="hljs-variable">$supercache_file</span> /wp-content/cache/supercache/<span class="hljs-variable">$http_host</span><span class="hljs-variable">$1</span>/index<span class="hljs-variable">${ihttp_host}</span>.html;
}
<span class="hljs-comment"># 只有当缓存文件存在时,才进行 rewrite</span>
<span class="hljs-keyword">if</span> (<span class="hljs-operator">-f</span> <span class="hljs-variable">$document_root</span><span class="hljs-variable">$supercache_file</span>) {
<span class="hljs-comment">#rewrite ^(.*)$ $supercache_file break;</span>
rewrite ^ <span class="hljs-variable">$supercache_file</span> last;
}
<span class="hljs-comment"># 所有其他请求,转给 wordpress 处理</span>
<span class="hljs-keyword">if</span> (!<span class="hljs-operator">-e</span> <span class="hljs-variable">$request_filename</span>) {
rewrite . /index.php last;
}
相关文章
- DNF单机版真100级真女鬼剑风法全职业三觉 Win7亲测可玩 (内含教程GM工具 需要虚拟机)
- 网络游戏 决战掉率列表
- 决战游戏地图坐标
- 决战数据库0nlineshop表NPC卖东西的
- 决战GameUser数据表详解说明 DROIYAN ONLINE
- 决战DROIYAN ONLINE 7.0版本怪物列表
- 决战DROIYAN ONLINE如何16进制刷刷教程
- 传奇教程 GOM引擎RMB地图脚本,传奇私服一条龙设置RMB点进入地图的方法 传奇脚本
- 传奇教程 GOM引擎转生地图脚本,传奇开区时添加需要转生进入地图的命令 传奇脚本
- 传奇教程 GOM引擎九零土豪脚本,传奇一条龙开区时添加VIP称号地图命令 传奇脚本