Forum: NGINX Redirecting based on cookie value

Posted by mschipperheyn (Guest)
on 2012-02-03 20:17
(Received via mailing list)
Hi,

I'm want to redirect the user based on the value of a cookie, if
present.

The scenario is one where there is a "starter" homepage for first time
users. As soon as users login, I write a cookie with the relative path
of another homepage. If the cookie is present, I want to redirect the
user to the cookie value: the relative path. There are multiple cookies
present in the request, such as session cookies.

I could of course, let the homepage be determined on the session on the
app server side, but since this is the landing page, I prefer to support
it with nginx reverse proxy caching. Hence the idea of using cookies to
redirect the user once he has logged in once.

Any ideas?

Marc

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,221965,221965#msg-221965
Posted by "António P. P. Almeida" <appa@perusio.net> (Guest)
on 2012-02-03 20:28
(Received via mailing list)
On 3 Fev 2012 19h16 WET, nginx-forum@nginx.us wrote:

> cookies.
>
> I could of course, let the homepage be determined on the session on
> the app server side, but since this is the landing page, I prefer to
> support it with nginx reverse proxy caching. Hence the idea of using
> cookies to redirect the user once he has logged in once.

Use map: http://nginx.org/en/docs/http/ngx_http_map_module.html

Here's a gist that implements a system where a user is redirected to a
HTTPS host if there's a session cookie. This is "blind" in the sense
that it doesn't capture any value of the cookie. But you can do that
easily with named captures in map.

https://gist.github.com/1695505

> Any ideas?

This may be helpful to you.

--- appa
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.