前篇WordPress/Nginx打开permalinks并安装Super Cache插件介绍了用if和rewrite实现wordpress的permalinks和super cache,但是,根据Nginx文档IfIsEvil的介绍,if语句由于实现的历史原因,在location上下文中工作并不正常。所以这里把if...set...放到location外的server上下文中,然后再用try_files标记代替原来的rewrite。
#首先还是WP/super cache配置文件wp-super-cache 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'; } location /blog { index index.html index.htm index.php; try_files /blog/wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /blog/index.php?$args ; }
这里假设WP安装在/blog目录下。其次是网站配置文件,包含wp-super-cache到server上下文中,需要注意的是WP对应的location已经放到wp-super-cache中了,所以网站配置文件中不再需要。如果WP不是虚拟目录的话,建议将root标记也放到server上下文中,这样php只需要配置一次.网站配置文件完整的server块如下:
listen 443; server_name localhost.localdomain; root /var/www; include wp-permalinks-super-cache; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
多网站/目录共享WP配置方法可以参考文档:http://codex.wordpress.org/Nginx
没有评论:
发表评论