基于引用的不同的nginx规则

我正在使用WP超级caching的WordPress。 我想要来自Google的访问者(包括所有国家/地区特定推荐人,如google.co.in,google.co.uk等)查看未caching的内容。

有我的nginx规则是不是我想要的方式:

server { server_name website.com; location / { root /var/www/html/website.com; index index.php; if ($http_referer ~* (www.google.com|www.google.co) ) { rewrite . /index.php break; } if (-f $request_filename) { break; } set $supercache_file ''; set $supercache_uri $request_uri; if ($request_method = POST) { set $supercache_uri ''; } if ($query_string) { set $supercache_uri ''; } if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) { set $supercache_uri ''; } if ($supercache_uri ~ ^(.+)$) { set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html; } if (-f $document_root$supercache_file) { rewrite ^(.*)$ $supercache_file break; } if (!-e $request_filename) { rewrite . /index.php last; } } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html/website.com$fastcgi_script_name; include fastcgi_params; } } 

我应该怎么做才能达到我的目标?

我对WP Supercache并不熟悉,但是如果你只是需要重写index.php来避免caching,那应该不会太难。

您现有的filter并不全面,因为它只会检查google.com和google.co。 根据这个清单 ,有很多谷歌使用的TLD不匹配,比如google.de,google.fr等。

以下过滤条件应将您限制为以www.google开头并以2-3个字符的TLD组合结尾的引荐来源。

 if ($http_referer ~* ^www.google.[az]{2,3}(.[az]{2})?$ ) { # do whatever you need to do here to avoid caching } 

你快到了

首先,WP超级caching规则非常混乱。 他们确实需要从头开始重新devise ,但这是另一个项目。

为了得到这个工作,不要立即返回,而是像所有其他检查那样设置$supercache_uri = '' 。 例如:

 if ($http_referer ~* (www.google.com|www.google.co) ) { set $supercache_uri ''; } 

这需要在最初set $supercache_uri地方出现,而不是在开始的地方。

这可能适用于$ http_referer:

  if ($http_referer ~* (www.google.com|www.google.co) ) { break; } if (!-e $request_filename) { rewrite . /index.php break; }