Welcome! Log In Create A New Profile

Advanced

Questions about solutions when using proxy_cache to redirect to cached pages for non logged in users.

Zev Blut
February 16, 2010 03:32AM
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?

* 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?

* 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.


Thanks,
Zev

The following is a roughly summarized view of my configuration.

----- nginx.conf --------
upstream app {
server 127.0.0.1:3000;
}

location / {
set $iflang "ja";
set $backend "not_logged_in_user";
if ($loggeduser) { set $backend "logged_in_user"; }
rewrite ^(.*)$ /$backend$1;
}

location ~ ^/not_logged_in_user/(.*)$ {
proxy_pass http://app/$1?$args;
proxy_cache one;
proxy_cache_key "$scheme$host$iflang$request_uri$args";
proxy_cache_valid 200 15m;
proxy_cache_valid 301 1h;
proxy_cache_use_stale updating error;

# Ideally would only like to pass through language_code cookie
proxy_pass_header Set-Cookie;

# Stop the browser from caching, try to just keep the caching on nginx.
proxy_hide_header Cache-Control;
}

location ~ ^/logged_in_user/(.*)$ {
proxy_pass http://app/$1?$args;
}
----- nginx.conf --------

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Questions about solutions when using proxy_cache to redirect to cached pages for non logged in users.

Zev Blut February 16, 2010 03:32AM

Re: Questions about solutions when using proxy_cache to redirect to cached pages for non logged in users.

Maxim Dounin February 16, 2010 05:08AM

Re: Questions about solutions when using proxy_cache to redirect to cached pages for non logged in users.

Zev Blut February 16, 2010 05:22AM

Re: Questions about solutions when using proxy_cache to redirect to cached pages for non logged in users.

Maxim Dounin February 16, 2010 05:28AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 311
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