WP Super Cache在Nginx网页服务器下的伪静态规则

虽然 LAMP 堆栈(Linux + Apache + MySQL + PHP)在为 WordPress 提供支持方面非常流行,但也可以使用 Nginx。 WordPress 支持 Nginx,一些大型 WordPress 网站(例如 WordPress.com)由 Nginx 提供支持。 在谈论 Nginx 时,重要的是要知道有多种方法来实现 Nginx。 它可以设置为 Apache 前面的反向代理,这是一个非常强大的设置,允许您使用 Apache 的所有功能和功能,同时受益于 Nginx 的速度。 大多数报告使用 Nginx 作为服务器的网站(基于从 HTTP 响应标头收集的统计数据)实际上是使用 Nginx 作为反向代理运行的 Apache。 (显示“Nginx”的 HTTP 响应标头是由反向代理而不是服务器本身报告的。) 本指南指的是独立的 Nginx 设置,它用作主服务器而不是 Apache。 需要注意的是,Nginx 并不是 Apache 的完全可互换的替代品。 在继续之前,您需要了解一些影响 WordPress 实施的关键差异: Nginx 没有像 Apache 的 .htaccess 或 IIS 的 web.config 文件那样的目录级配置文件。 所有配置都必须由管理员在服务器级别完成,并且 WordPress 无法像 Apache 或 IIS 那样修改配置。 运行 Nginx 时,Pretty Permalinks 功能略有不同。 由于Nginx没有.htaccess-type能力,并且WordPress无法自动为您修改服务器配置,因此它无法为您生成重写规则。

上述内容出自wordpress官方的解释,因为Nginx和Apache的技术区别,所以在使用WP Super Cache插件时,Apache的网页服务器WP Super Cache插件可以自行生成 .htaccess,使用Nginx的网页服务器时,就不能自动生成伪静态规则了。

如果你的网页服务器是Nginx,那么在WP Super Cache插件会有如下这样的提示:

WP Super Cache在Nginx网页服务器下的伪静态规则

为了方便直接设置Nginx的规则,这里将WP Super Cache在Nginx网页服务器下的伪静态规则,直接复制在下面方便大家取用。

# 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 ;
}   

将上述伪静态代码在面板主机里面进行设置即可。

原创文章,作者:Da Zhuang,如若转载,请注明出处:https://www.lidazhuang.cn/jiaocheng/1697.html

(1)
上一篇 2023年10月20日 下午2:40
下一篇 2023年10月26日 下午2:28

相关推荐

联系我