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 ;
	}   

参考资料

2 Comments

    1. 是mod_rewrite缓存模式的,为了追求速度牺牲了一点用户体验,应该所有用户都是不会记住cookies的……

发表评论

电子邮件地址不会被公开。 必填项已用*标注

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>