Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using wordpress with WP Super Cache, and this is my nginx rules:

server {
    server_name  website.com;
    location / {
        root   /var/www/html/website.com;
        index  index.php;
           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;
    }
}

But I need it uncached if visitor come from some website. (for example: from google.com and yahoo.com)

share|improve this question

2 Answers 2

This nginx module might do what you want.

share|improve this answer

you can try

server {
    server_name  website.com;
    location / {
        root   /var/www/html/website.com;
        index  index.php;
           if ($http_referer ~* (|google.com|google.co|yahoo.com|) ) {
                   rewrite . /index.php last;
           }
           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;
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.