Welcome! Log In Create A New Profile

Advanced

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

agentzh
February 15, 2011 11:28PM
On Wed, Feb 16, 2011 at 3:00 AM, Ryan Malayter <malayter@gmail.com> wrote:
> I very much see why "if is evil", but unfortunately there seems to be
> almost no alternative if you want to take some action based on things
> in headers or other variables.
>
> So what is a generally safe way to handle control flow where the
> conditions are based on something that is not in the URI (making
> rewrite useless)?
>

We've been using the ngx_lua module to do such complicated nginx.conf
branching (and also the whole application's business logic) in Lua.
Lua's "if" is not evil anyway.

> Note that changing the back-end application to handle things is often
> not possible when using commercial web applications behind nginx.
>

Indeed.

For our own business, the only "back-end application" is the mysql,
tokyotyrant, and memcached clusters (as well as many other such "true
backends"). We do use nginx as the "web application server" (in
contrast with the "web server"), and use Lua as the "application
language" :)

> I guess this sort of thing could always be a job for a general-purpose
> web server like Apache. Nginx is meant to be simple and lightweight;
> perhaps the general design is at odds with complex flow control.
>

Lua is a lightweight language and even backend daemons like Mysql
Proxy and TokyoTyrant embed it. LuaJIT 2.0 has made it even lighter ;)

Besides, for ngx_lua's set_by_lua directive, there's even no Lua
coroutine overhead (though the overhead itself is very small).

BTW, I did *not* say that you should never use nginx's if. Don't take
me wrong. My motivation of writing this explanation of the underlying
mechanism is to help you use it correctly and wisely ;)

I think Igor Sysoev will redesign the whole rewrite module in his
nginx 2.0 devel branch. Then everything will be changed.

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: 226
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