Questions about solutions when using proxy_cache to redirect to cached pages for non logged in users.
Maxim Dounin
mdounin at mdounin.ru
Tue Feb 16 12:59:13 MSK 2010
Hello!
On Tue, Feb 16, 2010 at 05:25:43PM +0900, Zev Blut wrote:
> Hello,
>
> I am trying out the proxy_cache commands in nginx. The recent mails
> on the mailing list have been quite helpful for figuring out what to
> do. I am able to use nginx to cache pages for non logged in users and
> have logged in users go directly to the backend.
>
> I have a few questions about if I am calling proxy_pass correctly, and
> if I can use proxy_pass_header to only let a certain Set-Cookie header
> through.
>
> * in location / I rewrite to either the logged in or not logged in states.
> But, I have to explicitly regex catch the real uri and add the args
> to the proxy pass.
> i.e.
>
> http://example.com/search?keword=nginx
>
> would lose the ?keyword=nginx if I just used
> proxy_pass http://app/$1
>
> Is my solution for calling "proxy_pass http://app/$1?$args;" correct?
This should work, but it's just waste of cpu. Use
location /not_logged_in_user/ {
proxy_pass http://app/;
...
}
instead.
> * For not logged in users I would only like to let the cookie
> "language_code"
> through and block any other cookies. Is that possible in nginx?
Well, you may try to do so via
proxy_set_header Cookie "language_code=$cookie_language_code";
but I don't think it's good idea.
> * On a side note, the site has the same uri for multiple languages.
> So when a user changes the site's language I am able to have nginx
> properly cache based on the language. Except the user's web browser
> will keep a cached copy of the first language, which can create a
> confusing experience. So far my solution is to striping the
> Cache-Control from the response header. This way nginx keeps a copy of
> the page in its' cache, but the web browser will not. I am wondering
> if there is a better solution.
You have to add Vary header with appropriate values for browsers.
See here:
http://tools.ietf.org/html/rfc2616#section-14.44
Maxim Dounin
More information about the nginx
mailing list