【发布时间】: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;
}
【问题讨论】: