【问题标题】:Same Nginx FastCGI Cache Conf, works on previous sites but not this one相同的 Nginx FastCGI 缓存配置,适用于以前的站点,但不适用于这个站点
【发布时间】:2018-11-13 11:18:08
【问题描述】:

我将相同的 nginx fastcgi 缓存配置应用于我目前正在处理的网站,但失败了,但在我以前的网站上运行良好。

总是错过,当登录被绕过。

所有网站都是 wordpress + woocommerce

当前站点的nginx版本是1.12.2,其他都是1.10.2

这里是配置:

fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=WordPress:500m inactive=360m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie X-Accel-Expires X-Accel-Redirect;
server{
    ......#other codes

    add_header X-Cache $upstream_cache_status;

    ......#other codes

    #Cache everything by default
    set $no_cache 0;

    #Don't cache POST requests
    if ($request_method = POST)
    {
        set $no_cache 1;
    }

    #Don't cache if the URL contains a query string
    if ($query_string != "")
    {
        set $no_cache 1;
    }

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

    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
        set $no_cache 1;
    }

    #Don't cache if there is a cookie called PHPSESSID
    if ($http_cookie = "PHPSESSID")
    {
        set $no_cache 1;
    }

    if ($http_cookie ~* "(wordpress_logged_in_|wp\-postpass_|woocommerce_items_in_cart|woocommerce_cart_hash)")
    {
        set $no_cache 1;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php-fpm;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_cache_bypass $no_cache;
        fastcgi_no_cache $no_cache;
        fastcgi_cache WordPress;
        fastcgi_cache_valid 200 360m;
    }

【问题讨论】:

    标签: nginx fastcgi


    【解决方案1】:

    经过几天的反复试验,我发现了一个小点,权限后面的点,如下所示:drwxr-x---。

    我搜索了一下,原来是selinux相关的。我当前的站点安装并启用了 selinux,它对 nginx 的策略导致 nginx fastcgi 缓存不起作用。

    所以解决办法是让nginx fastcgi缓存位置符合selinux策略(httpd_t)。

    【讨论】:

      猜你喜欢
      • 2022-08-21
      • 2013-01-27
      • 2016-02-06
      • 1970-01-01
      • 2016-11-25
      • 1970-01-01
      • 1970-01-01
      • 2013-02-09
      • 1970-01-01
      相关资源
      最近更新 更多