我对当前正在使用的网站应用了相同的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;
}
答案 0 :(得分:0)
经过几天的反复试验,我发现了一个小点,即权限后面的点,例如:drwxr-x ---。
我搜索了一下,结果发现它与selinux有关。我当前的站点已安装并启用了selinux,其对nginx的策略导致nginx fastcgi缓存不起作用。
因此,解决方案是使nginx fastcgi缓存位置符合selinux策略(httpd_t)。