分享互联网知识,建站、IT话题杂谈

Wp Super Cache + Nginx规则

从Nginx+Apache搭配(Leamp脚本)切换成Nginx单独作为前端(Lemp脚本)之后,Wp Super Cache原有的规则也需要进行更新,否则生成的缓存文件还是需要经过数据库查询。下面将Nginx的规则记录一下,以供参考

编辑网站的Nginx配置文件,如果您使用我的脚本,配置文件位于/etc/nginx/conf.d/yourdomain.com

	# Rest of your config lines above
	set $cache_uri $request_uri;

	# POST requests and urls with a query string should always go to PHP
	if ($request_method = POST) {
		set $cache_uri 'null cache';
	}   
	if ($query_string != "") {
		set $cache_uri 'null cache';
	}   

	# 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/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
		set $cache_uri 'null cache';
	}   

	# Don't use the cache for logged in users or recent commenters
	if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
		set $cache_uri 'null cache';
	}

	# Use cached or actual file if they exists, otherwise pass request to WordPress
	location / {
		try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php ;
	}   

参考资料

Leave a comment

Your email address will not be published. Required fields are marked *

2 thoughts on “Wp Super Cache + Nginx规则”