WP Super Cache와 함께 WordPress를 사용하고 있습니다. Google에서 온 방문자 (Google.co.in, google.co.uk 등의 모든 국가 별 추천자 포함)가 캐시되지 않은 콘텐츠 를 보길 원합니다 .
원하는 방식으로 작동하지 않는 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로 다시 작성 해야하는 경우 너무 어렵지 않아야합니다.
기존 필터는 google.com 및 google.co 만 검사하므로 포괄적이지 않습니다. 이 목록 에 따르면 google.de, google.fr 등과 같이 Google에서 사용하지 않는 TLD가 많이 있습니다.
다음 필터는 www.google로 시작하고 2-3 자 TLD의 조합으로 끝나는 리퍼러로 제한해야합니다.
if ($http_referer ~* ^www.google.[a-z]{2,3}(.[a-z]{2})?$ ) {
# do whatever you need to do here to avoid caching
}
답변
거의 다 왔습니다.
첫째, WP Super Cache 규칙은 매우 복잡합니다. 그들은 처음부터 다시 디자인해야 하지만, 그것은 다른 날의 프로젝트입니다.
이 작업을 수행하려면 즉시 반환하지 말고 대신 $supercache_uri = ''
다른 모든 검사와 마찬가지로 설정하십시오 . 예를 들어 :
if ($http_referer ~* (www.google.com|www.google.co) ) {
set $supercache_uri '';
}
이것은 시작 위치가 아니라 $supercache_uri
원래 위치 이후에 나타나야 set
합니다.
답변
이것은 $ http_referer에서 작동 할 수 있습니다 :
if ($http_referer ~* (www.google.com|www.google.co) ) {
break;
}
if (!-e $request_filename) {
rewrite . /index.php break;
}
답변
이 시도
if ($http_referer ~* (www.example.com|example.com.au) ) {
return 301 http://your-url.example/custom-path;
}