break; usage

Igor Sysoev is at rambler-co.ru
Thu Sep 6 23:38:52 MSD 2007


On Thu, Sep 06, 2007 at 03:22:40PM -0400, Jonathan Dance wrote:

> I was wondering if anyone could clarify what "break;" does - basically, does
> it stop all processing, or only rewrite processing? What is its effect on
> proxy_pass? Here are two simple contrasting examples:

The "break" stops rewrite module processing only.

> location / {
>   if (!-f $request_filename) {
>     proxy_pass http://somewhere;
>     break; # does this do anything?
>   }
> }

Here nginx runs "if" internal opcode, then "break" stops rewrite module
execution. nginx uses static configuration inside "if" block.
This configuration inherits all inheritable directives from previous
levels (and defaults) and defines the single "proxy_pass" directive.
So nginx will go to proxy module.

> # Is that any different from this?
> 
> location / {
>   if (-f $request_filename) {
>     break; # avoid the proxy_pass?
>   }
>   proxy_pass http://somewhere;
> }

Here nginx runs "if" internal opcode, then "break" stops rewrite module
execution. nginx uses static configuration inside "if" block.
This configuration inherits all inheritable directives from previous
levels (and defaults). The "proxy_pass" directive is not inheritable,
so nginx go to static module.
If "if" condition was false, then nginx uses static configuration
inside "localtion /", but outside "if", i.e. - "proxy_pass", etc..

The current rewrite module state is ugly. This static configuration
inside "if" blocks are terrible.

I'm going to drop rewrite module and replace it with script module, that

1) will allow only to set variables inside "if" blocks

2) will allow to use script in different request processing phases:

    location / {
        script << {  # URI rewrite phase
           ...
        }

        script {  # content generation phase
           ...
        }

        script >> { # post content generation phase
           ...
        }


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list