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

参考资料

天毅

Linux/php菜鸟,喜欢修修补补,喜欢分享,喜欢写博客,其实主要是喜欢找速度快的国外空间(剁手癌晚期,买VPS完全停不下来)...

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

发表评论

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