Welcome! Log In Create A New Profile

Advanced

Re: How nginx's "location if" works (Was Re: Setting cache parameter via if directives)

agentzh
February 19, 2011 01:10AM
On Fri, Feb 18, 2011 at 8:29 PM, Alexander Kunz <akunz@ntmedia.de> wrote:
> Time to think a bit different :) The "old" way still stuck in my head. I see
> there is a function access_by_lua but i still like session. Could this the
> way to handle access to all files in app?

Sure :)

> Decrypt session and encrypt
> session for refreshing the session livetime?

Yeah :)

> Or shoud i use access_by_lua in
> each location?
>

Well, this is a valid option too: you can combine
ngx_encrypted_session and access_by_lua by calling
ngx_ecrypted_session's config directives directly from within Lua,
like this:

access_by_lua '
local encrypted_text = ndk.set_var.set_decode_base32(ngx.var.arg_session)
if not encrypted_text or encypted_text == "" then
return ngx.redirect("/relogin.htm?url=" ..
ngx.escape_uri(ngx.var.uri))
end

local raw_text = ndk.set_var.set_decrypt_session(encrypted_text)
if not raw_text or raw_text == "" then
return ngx.redirect("/relogin.htm?url=" ..
ngx.escape_uri(ngx.var.uri))
end

-- validate raw_text is indeed valid...

-- then refresh the sessions:
local encrypted_text = ndk.set_var.set_encrypt_session(raw_text)
local value = ndk.set_var.set_encode_base32(encrypted_text)
ngx.header["Set-Cookie"] = { "SID=" .. value .. "; path=/" }
';

A very useful feature in ngx_lua is the "ndk.set_var.xxx" magic that
allows you to call some other nginx C modules' config directives
on-the-fly! There's a restriction though: the 3rd-party directives
must be implemented using NDK (Nginx Devel Kit)'s set_var submodule's
ndk_set_var_value mechanism ;)

>
> Have a nice day, agentzh.
>

You too! ;)

Cheers,
-agentzh

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

How nginx's "location if" works (Was Re: Setting cache parameters via if directives)

agentzh February 14, 2011 12:30AM

Re: How nginx's "location if" works (Was Re: Setting cache parameters via if directives)

António P. P. Almeida February 14, 2011 05:32PM

Re: How nginx's "location if" works (Was Re: Setting cache parameters via if directives)

Eugaia February 14, 2011 06:52PM

Re: How nginx's "location if" works (Was Re: Setting cache parameters via if directives)

Ryan Malayter February 15, 2011 02:04PM

Re: How nginx's "location if" works (Was Re: Setting cache parameters via if directives)

Dayo February 15, 2011 02:23PM

Re: How nginx's "location if" works (Was Re: Setting cache parameters via if directives)

Dayo February 15, 2011 02:27PM

Re: How nginx's "location if" works (Was Re: Setting cache parameters via if directives)

agentzh February 15, 2011 11:28PM

Re: How nginx's "location if" works (Was Re: Setting cache parameter via if directives)

Alexander Kunz February 18, 2011 06:22AM

Re: How nginx's "location if" works (Was Re: Setting cache parameter via if directives)

agentzh February 18, 2011 06:58AM

Re: How nginx's "location if" works (Was Re: Setting cache parameter via if directives)

agentzh February 18, 2011 06:58AM

Re: How nginx's "location if" works (Was Re: Setting cache parameter via if directives)

Alexander Kunz February 18, 2011 07:34AM

Re: How nginx's "location if" works (Was Re: Setting cache parameter via if directives)

Justin Cormack February 18, 2011 08:26AM

Re: How nginx's "location if" works (Was Re: Setting cache parameter via if directives)

agentzh February 19, 2011 01:10AM

Re: How nginx's "location if" works (Was Re: Setting cache parameter via if directives)

Alexander Kunz February 19, 2011 05:46AM

Re: How nginx's "location if" works (Was Re: Setting cache parameters via if directives)

seekvn September 28, 2021 04:57AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 38
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready