WordPress 使用 WP Super Cache 部分请求传递参数 query_string

建站 码拜 4年前 (2019-11-19) 1841次浏览 0个评论

为了提升WordPress网站的响应速度,降低服务器的负载压力,为网站使用了插件  WP Super Cache 用于生成静态文件,配置按照nginx的官方示例进行配置。

set $cache_uri $request_uri;

    # POST requests and URLs with a query string should always go to PHP
    # POST 的请求和带参数的请求都通过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(-+([a-zA-Z0-9_-]+))?\.(xml|
xml.gz|html|html.gz))") {
        set $cache_uri 'null cache';
    }  
	
    # Don't use the cache for logged-in users or recent commenters
    # 对于已登录用户不缓存 本文首发原创 www.codebye.com 版权所有
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
        set $cache_uri 'null cache';
    }

    # Use cached or actual file if it exists, otherwise pass request to <a href="https://www.codebye.com/tag/wordpress" title="查看更多关于WordPress的文章" target="_blank">WordPress</a>
    # 当其他连接访问Wordpress的时候通过下面的路径找到缓存文件的地址,访问缓存页面
    location / {
        try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html 
                  $uri $uri/ /index.php;
    }

一直使用的以上配置,没发现问题,近期接入了微信小程序,发现许多Rest api请求无效,提示“rest_missing_callback_param 缺少参数:openid”,最后查到的原因是参数丢失了。
为nginx 的配置文件增加了如下配置,微信小程序功能恢复正常。
WordPress 使用 WP Super Cache 部分请求传递参数 query_string

location ^~ /wp-json/ {
  # 匹配任何以 /wp-json/ 开头的地址,匹配符合以后,停止往下搜索正则,采用这一条。
  try_files $uri $uri/ /index.php?$query_string;
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明WordPress 使用 WP Super Cache 部分请求传递参数 query_string
喜欢 (1)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!