LinuxEye - Linux系统教程

LinuxEye - Linux系统教程

当前位置: 主页 > 建站 >

Ngnix配置完美支持WordPress wp-super-cache插件

时间:2015-08-27 22:22来源:未知 编辑:linuxeye 点击:
配置Wordpress wp Super Cache缓存插件 nginx服务器无法开启wp Super Cache的Mod_Rewrite缓存模式? Nginx 是俄罗斯开发的高性能反向代理服务器。特点是占有内存少,并发能力强,对于静态页面的处理
配置Wordpress wp Super Cache缓存插件 nginx服务器无法开启wp Super Cache的Mod_Rewrite缓存模式?

Nginx
是俄罗斯开发的高性能反向代理服务器。特点是占有内存少,并发能力强,对于静态页面的处理效率已远超同类产品。在国内各大互联网公司也在使用,比如 新浪、网易、 腾讯 等。

WP Super Cache
wordpress官方打造的高速缓存插件,为wordpress生成静态的html文件。 内置的丰富选项也可以方便我们的日常管理。比如缓存文件的列表。缓存权限配置等等。 提供的缓存方式有3种:Mod_Rewrite、PHP、Legacy caching 好了。介绍完毕。下面就是如何对nginx进行配置使我们的wordpress在nginx上使用WP Super Cache的Mod_Rewrite模式。 英语好的同学可以先打开这篇文章看一下:wordpress-nginx设置。 不看也没关系。

我这里的服务器环境:《lnmp一键安装包

首先在wordpress下安装wp Super Cache
后台直接搜索安装即可,启用缓存,选择Mod_Rewrite模式。会提示出信息
  • Mod rewrite 模块可能未安装! 貌似 mod_rewrite 模块尚未安装。也许情况并不是这样,尤其是当您不使用 Apache 作为服务器程序的时候。请检查 mod_rewrite 模块是否被加载。这对于 Super Cache 的静态文件的调用是必需的。不过您可以使用 PHP 缓存模式或者传统模式运行本插件。
  • 重写规则必须被更新 插件需要的重写规则已被更改或者缺失。 滚动查看高级选项卡,找到并点击 更新 Mod_Rewrite 规则 按钮。

接下来我们需要做的是修改nginx重写的规则(wordpress.conf)
# WP Super Cache rules.
# Designed to be included from a 'wordpress-ms-...' configuration file.

set $cache_uri $request_uri;

# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
        set $cache_uri 'null cache';
}
   
if ($query_string != "") {
        set $cache_uri 'null cache';
}   

# Don't cache uris containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
        set $cache_uri 'null cache';
}   

# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
        set $cache_uri 'null cache';
}

# START MOBILE
# Mobile browsers section to server them non-cached version. COMMENTED by default as most modern wordpress themes including twenty-eleven are responsive. Uncomment config lines in this section if you want to use a plugin like WP-Touch
# if ($http_x_wap_profile) {
#        set $cache_uri 'null cache';
#}

#if ($http_profile) {
#        set $cache_uri 'null cache';
#}

#if ($http_user_agent ~* (2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800)) {
 #       set $cache_uri 'null cache';
#}

#if ($http_user_agent ~* (w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-)) {
  #      set $cache_uri 'null cache';
#}
#END MOBILE

# Use cached or actual file if they exists, otherwise pass request to WordPress
location / {
        try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?$args ;
}
出现以上命令就说明配置文件没问题了。 现在我们刷新当前页面,右键打开源码。在源码内看到 这样一句话就证明WP-Super-Cache 已经应用了。 在WP-Super-Cache设置的那个页面。出现文章开头所说的那两个提示不用理会。 下面列一下我在WP-Super-Cache设置的勾选选项
√ 启用缓存以便加快访问。 (推荐)
√ mod_rewrite 缓存模式。 (推荐)
√ 不要为已知用户缓存。 (推荐)
√ 不要为 GET 请求缓存。(地址结尾为?x=y)
√ 当有新文章或页面的发布或更新时清除之前的缓存文件。
√ 当某页面有新评论时,只刷新该页面的缓存。
------分隔线----------------------------
标签:WordPressNgnixwp-super-cac
栏目列表
推荐内容