break; usage

Igor Sysoev is at rambler-co.ru
Fri Sep 7 00:07:54 MSD 2007


On Thu, Sep 06, 2007 at 03:52:37PM -0400, Jonathan Dance wrote:

> Thanks very much for the reply, Igor.
> If I understand your explanation (which was most excellent), the blocks
> would result in nearly identical results, but not because of the "break"
> directive; it is identical because "proxy_pass" does not get inherited to
> the "if" block. Additionally, since there are no rewrites, the "break"
> directive has no effect. Is that correct?

Yes, but the "break" has meaning in following configuration:

    if (A) {
        proxy_pass   AAAA;
        #break;
    }

    if (B) {
        proxy_pass   BBBB;
    }

If both conditions are true, then without "break" in A nginx will always
go to BBBB, becuase nginx will run rewrite opcodes in following order:

    evalute A
    if opcode
       set A block as current configuraiton
    evalue B
    if opcode
       set B block as current configuraiton

and resulting configuration is B.


nginx has three types of directives:

1) static, e.g. 'root /var/www'
2) dynamic - if, rewrite, set, break
3) and semi-dynamic, e.g. 'root $var'.


> It does sound like a refactoring is in order. In Igor we trust! :)
> 
> JD
> 
> On 9/6/07, Igor Sysoev <is at rambler-co.ru> wrote:
> >
> > 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/
> >
> >

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





More information about the nginx mailing list