I am using page caching on a rails site and I want a logged-in admin
to be served the non-cached site. This needs to be done in our nginx
config but I haven’t been able to get anything to work.
My first (and most logical) attempt was to set a cookie for admins and
have a
conditional statement in the nginx config that checks for
that cookie. If it finds it, it should go directly to the proxy_pass.
Here is what that looked like:
if ($http_cookie ~* "nocached=true") {
proxy_pass http://mongrel;
break;
}
This did not work. If I put a rewrite line in that conditional
statement, it works. That means it is recognizing the cookie
correctly and that there is a problem with my approach. I think I
might need to use different syntax to use only the mongrels and not
load the cached pages but I don’t know what that would look like. If
you have tried something like this, I’d love to hear what you found.
Thanks!
if ($http_cookie ~* “nocached=true”) {
you have tried something like this, I’d love to hear what you found.
Thanks!
It might be working… mongrel will serve up files cached into public as
well. So the above might very well be handing it to mongrel, mongrel
sees
the cached file and serves it up on it’s own.
if ($http_cookie ~* “nocached=true”) {
you have tried something like this, I’d love to hear what you found.
Thanks!
It might be working… mongrel will serve up files cached into public as
well. So the above might very well be handing it to mongrel, mongrel sees
the cached file and serves it up on it’s own.
-philip
Wow, I had not considered that. I will change the location of the
cached pages to public/cache and have nginx serve cached pages from
there. That way, Mongrel won’t recognize that there are static files
for the requests. I will let you know if that works. Thanks philip!
might need to use different syntax to use only the mongrels and not
Wow, I had not considered that. I will change the location of the
cached pages to public/cache and have nginx serve cached pages from
there. That way, Mongrel won’t recognize that there are static files
for the requests. I will let you know if that works. Thanks philip!
Alright, that did the trick. The only other problem I ran into is
that the $request_filename variable is an absolute path. I had been
trying to use that variable in a path like $document_root/cache/
$request_filename.html - this didn’t work, I had to use the $uri
variable instead: $document_root/cache/$uri.html
Thanks again!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.