Welcome! Log In Create A New Profile

Advanced

WP Super Cache: "try_files" aren't allowed in "if" blocks

Igor Clark
September 24, 2009 05:48PM
Hi there, hope you're all well!

I'm trying to configure nginx for the Wordpress Super Cache plugin,
using the "Don't cache pages for logged in users" option.

I have the following config which works well once the cached file has
been generated:

location ~ ^/my-blog(.*)$ {
try_files $uri $uri/
/my-blog/wp-content/cache/supercache/$http_host/$uri/index.html
/my-blog/index.php;
}

but I don't want to serve the cached file to logged-in users, which
according to the WPSC documentation can be found by checking the cookie
for "(comment_author_|wordpress|wp-postpass_)".

The following snippet I found on this list doesn't work with nginx
0.7.61 (and nothing I see in the 0.7.62 changelog appears relevant):

location ~ ^/my-blog(.*)$ {
if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_") {
try_files $uri $uri/ /my-blog/index.php;
break; # BTW, would this be necessary if it did work?
}
try_files $uri $uri/
/my-blog/wp-content/cache/supercache/$http_host/$uri/index.html
/my-blog/index.php;
}

because apparently "try_files" is not allowed inside "if":

[emerg]: "try_files" directive is not allowed here

So I tried this:

location ~ ^/my-blog(.*)$ {
if ($http_cookie !~* "comment_author_|wordpress|wp-postpass_") {
rewrite ^/my-blog/(.*)$
/my-blog/wp-content/cache/supercache/$http_host/my-blog/$1/index.html
break;
}
try_files $uri $uri/ /my-blog/index.php;
}

and that works fine once the cached file has been generated, but
obviously returns 404 beforehand.

I know I could just add

if ($http_cookie !~* "comment_author_|wordpress|wp-postpass_") {
if(-e [cached file]) {
rewrite …;
}
}

but that would seem to defeat the object of using try_files to get away
from these if() constructions.

Is there a way to check cookie values more like a location test, or
even, or is there a better way to do what I'm trying to do?

Thanks for your help,
Igor Clark
--
Posted via http://www.ruby-forum.com/.
Subject Author Posted

WP Super Cache: "try_files" aren't allowed in "if" blocks

Igor Clark September 24, 2009 05:48PM

Re: WP Super Cache: "try_files" aren't allowed in "if" blocks

Maxim Dounin September 25, 2009 05:50AM

Re: WP Super Cache: "try_files" aren't allowed in "if" block

Igor Clark September 25, 2009 04:02PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 148
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready