Trouble with a complex rewrite
Wilson Bilkovich
wilsonb at gmail.com
Tue Apr 3 01:11:21 MSD 2007
On 4/2/07, Igor Sysoev <is at rambler-co.ru> wrote:
> On Mon, Apr 02, 2007 at 03:55:20PM -0400, Wilson Bilkovich wrote:
>
> > I have two more questions about this:
> > 1. I can use any regular expression supported by PCRE, anywhere in my
> > nginx config, correct?
>
> The regexp engine is PCRE.
>
> The regexp are supported in some directives only:
> "if", "rewrite", and "location".
>
> > 2. When I have nested locations, such as:
> > location / {
> > location /api/receive {
> > break;
> > }
> > some_config_option on;
> > }
> >
> > Configuration options in the outer scope (location /, in this case)
> > are always evaluated, despite the break command?
> > In other words, break only 'breaks' from the location / rewrite loop,
> > not from the rest of the configuration?
>
> If the "rewrite" directive has rewritten URI, then nginx search the new
> location configuration. The "break" stops this rewrite cycle.
>
> The nested locations are not fully supported, you should use
>
> location / {
> ...
> }
>
> location /api/receive {
> ...
> }
>
>
Sorry to belabor the point, but this is really helping me understand.
location / {
set $once = "once";
if ($once) {
set $once = "";
rewrite ^ /once break;
}
set $once = "twice";
rewrite /once /twice break;
}
Given that code (assuming it is valid.. if not, let's pretend I wrote
it correctly).
I would expect that a request for example.com/ would be rewritten to
example.com/once, and that the value of $once would be 'twice'.
Am I correct about that? My understanding is that break cancels any
further rewrites, but has no effect on the other configuration
statements that come after it.
--Wilson
More information about the nginx
mailing list