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

Alexander Kunz akunz at
Fri Feb 18 15:29:35 MSK 2011

Thanks so much for the detailed answer.

So i think i am on the right way using html + jquery. The HTML page 
loads all my css + js + static data  and jquery loads the content with 
ajax calls. The Browser builds the page. Nginx + Lua + Redis and the 
whole application flys... Great :)

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? Decript session and 
encrypt session for refreshing the session livetime? Or shoud i use 
access_by_lua in each location?

     location /app {

         set_decode_base32 $session $cookie_SID;
         set_decrypt_session $raw $session;
         set_encrypt_session $session $raw;
         set_encode_base32 $session;
         add_header Set-Cookie "SID=$session; path=/";

         if ($raw = '') {
             rewrite (.*) /relogin.htm?url=$1 redirect;

         try_files $uri $uri/;

Have a nice day, agentzh.


On 18.02.2011 12:55, agentzh wrote:
> On Fri, Feb 18, 2011 at 7:54 PM, agentzh<agentzh at>  wrote:
>>     local data = get_data_from_remote()
>>     local html = generate_html_from_template("/path/to/my/template")
> Sorry, the last line should have been
>     local html = generate_html_from_template(data, "/path/to/my/template")
> Cheers,
> -agentzh

More information about the nginx mailing list