我为Nginx创build了映射规则以避免caching。 但是它不起作用nocache_map.conf(包含在http部分。
map $http_x_requested_with $nocache { default 0; XMLHttpRequest 1; } map $http_cookie $nocache { default 0; SESS 1; PHPSESSID 1; ~*wordpress_[a-zA-Z0-9-].* 1; comment_author 1; wp-postpass 1; _mcnc 1; } map $request_uri $nocache { default 0; ~*\/wp-admin\/.* 1; ~*\/wp-[a-zA-Z0-9-]+\.php 1; ~*\/feed\/.* 1; ~*\/administrator\/.* 1; } map $http_user_agent $nocache { default 0; ~*android|ip(hone|od)|windows\s+(?:ce|phone) 1; ~*symbian|sonyericsson|samsung|lg|blackberry 1; ~*mobile 1; } map $request_method $nocache { default 0; POST 1; #no caching on post }
这些规则工作正常nocache.conf。
#Cache everything by default set $nocache 0; #Don't cache POST requests if ($request_method = POST) { set $nocache 1; } #Don't cache if the URL contains a query string if ($query_string != "") { set $nocache 1; } # Ajax if ($http_x_requested_with = XMLHttpRequest) { set $nocache 1; } # WordPress section start # 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/|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") { set $nocache 1; } # Don't use the cache for logged in users or recent commenters if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in*|_mcnc") { set $nocache 1; } # WordPress section end if ($http_user_agent ~* "android|ip(hone|od)|windows\s+(?:ce|phone)|symbian|sonyericsson|samsung|lg|blackberry|mobile") { set $nocache 1; }
服务器configuration
server { listen 80; include nocache.conf ... location / { try_files $uri $uri/ /index.php?$args; } location ~ ^.+\.php(?:/.*)?$ { try_files $uri $uri/ /index.php$is_args$args; fastcgi_split_path_info ^(.+.php)(.*)$; fastcgi_no_cache $nocache $cookie_nocache; fastcgi_cache_bypass $nocache $cookie_nocache; ....
caching工作正常只是地图的规则不起作用你能帮我find哪里是错误的? 谢谢。
你用map指令多次声明相同的variables,所以当nginx在fastcgi_no_cache或fastcgi_cache_bypass指令的上下文中计算这个variables时,它只会使用一个地图块。
声明不同的variables并在这些指令中使用它们。