【问题标题】:FastCGI cache key while ignoring GET requests but allow certain GET requests to bypass cacheFastCGI 缓存键同时忽略 GET 请求但允许某些 GET 请求绕过缓存
【发布时间】:2017-12-10 06:26:12
【问题描述】:

我有一个在 Woocommerce 上运行的 WordPress 安装,它需要 GET 请求 add_to_cart 才能运行,以便用户将商品添加到购物车。

我有类似的 FastCGI 缓存键 How to set fastcgi_cache_key using original $request_uri without $args?

# Map request_path var without query strings
map $request_uri $request_path {
    ~(?<captured_path>[^?]*) $captured_path;
}

# FastCGI Cache
fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_path$cookie_aelia_cs_selected_currency";

有没有办法绕过 FastCGI 处理这些请求,让 NGINX 只为页面提供服务?

我对 NGINX 还是很陌生,因此非常感谢任何帮助

更新

我尝试在服务器块中使用以下内容

if ($arg_name ~* "(add-to-cart|remove-item)") {
        set $no_cache 1;
}

服务器仍然忽略这一点并提供缓存文件。

现已解决

【问题讨论】:

    标签: wordpress caching nginx


    【解决方案1】:

    最终通过在请求检查中添加.*add-to-cart.* 解决。

    # Don't cache uris containing the following segments
    if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml|.*add-to-cart.*") {
        set $no_cache 1;
    }
    

    【讨论】:

      猜你喜欢
      • 2015-03-09
      • 1970-01-01
      • 2023-04-02
      • 2018-07-25
      • 2015-01-12
      • 1970-01-01
      • 1970-01-01
      • 2019-07-12
      • 2016-10-04
      相关资源
      最近更新 更多