Different nginx rules based on referrer

Posted by juana on Server Fault See other posts from Server Fault or by juana
Published on 2010-09-02T11:32:22Z Indexed on 2012/06/19 3:18 UTC
Read the original article Hit count: 438

Filed under:

I'm using WordPress with WP Super Cache. I want visitors who come from Google (That inlcudes all country specific referrers like google.co.in, google.co.uk and etc.) to see uncached contents.

There are my nginx rules which are not working the way I want:

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

What should I do to achieve my goal?

© Server Fault or respective owner

Related posts about nginx