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've just started using nginx and I'm now trying to make it play nice with the Wordpress plugin WP-SuperCache which adds static files of my blog posts.

To serve the static file I need to make sure that some cookies aren't set, that it's not a POST-request and making sure the cached/static file exist.

I found this guide and it seems like a good fit.

But I've noticed that as soon as I try to set something inside an if my site starta giving 404s on an URL that isn't rewritten.

The location block of the configuration:

location /blog {
    index index.php;

    set $supercache_file '';
    set $supercache_ok 1;

    if ($request_method = POST) {
        set $supercache_ok 0;
    }

    if ($http_cookie ~* "(comment_author_|wordpress|wp-postpass_)") {
        set $supercache_ok '0';
    }

    if ($supercache_ok = '1') {
        set $supercache_file '$document_root/blog/wp-content/cache/supercache/$http_host/$1/index.html.gz';
    }

    if (-f $supercache_file) {
        rewrite ^(.*)$ $supercache_file break;
    }

    try_files $uri $uri/ @wordpress;
}

The above doesn't work, and if I remove all the ifs above and add

if ($http_host = 'mydomain.tld') {
    set $supercache_ok = 1;
}

and then I get the exact same message in the errors.log. Namely:

2010/05/12 19:53:39 [error] 15977#0: *84 "/home/ba/www/domain.tld/blog/2010/05/blogpost/index.php" is not found (2: No such file or directory), client: <ip>, server: domain.tld, request: "GET /blog/2010/05/blogpost/ HTTP/1.1", host: "domain.tld", referrer: "http://domain.tld/blog/"

Remove the if and everything works as it should. I'm stymied, no idea at all where I should start searching. =/

ba@cell: ~> nginx -v
nginx version: nginx/0.7.65
share|improve this question
    
I got this working by removing the try_files line and changing it to using rewrite instead. Got it working but I'd still really like to know what messed things up since try_files worked as long as I didn't have any conditionals. –  gaqzi May 13 '10 at 14:32

1 Answer 1

I'm not entirely clear what the problem is either, but I am relatively sure the answer is some particular subtlety involving http://wiki.nginx.org/IfIsEvil .

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.