rewrite rule
Maxim Dounin
mdounin at mdounin.ru
Sun Jul 20 23:58:47 MSD 2008
Hello!
On Sat, Jul 19, 2008 at 02:53:57PM +0200, Chavelle Vincent wrote:
>There has been a change of behaviour on the rewrite rule between version
>0.7.1 and higher... I don't know if it's a bug or a correction !
>
>You can view a configuration type here : http://pastebin.com/f49df278c
>And the beginning of the debug file : http://pastebin.com/f547dc485
>
>The end:
>
>Version 0.7.1 (good behaviour)
>2008/07/19 14:17:07 [debug] 31892#0: *1 http script regex:
>"^/fallback(.*)$"
>2008/07/19 14:17:07 [debug] 31892#0: *1 http script capture:
>"/users/test"
>2008/07/19 14:17:07 [debug] 31892#0: *1 http script regex end
>2008/07/19 14:17:07 [debug] 31892#0: *1 post rewrite phase: 3
>2008/07/19 14:17:07 [debug] 31892#0: *1 uri changes: 10
>2008/07/19 14:17:07 [debug] 31892#0: *1 using configuration "/fallback/"
>2008/07/19 14:17:07 [debug] 31892#0: *1 http cl:-1 max:1048576
>2008/07/19 14:17:07 [debug] 31892#0: *1 generic phase: 2
This isn't correct behaviour, it's bug introduced in 0.7.1 and
fixed in 0.7.2. Your rewrite directive in location /fallback/
changed the request uri, but nginx failed to do correct search of
new location to use.
>Version 0.7.6
>2008/07/19 14:24:02 [debug] 32178#0: *1 http script regex:
>"^/fallback(.*)$"
>2008/07/19 14:24:02 [debug] 32178#0: *1 http script capture:
>"/users/test"
>2008/07/19 14:24:02 [debug] 32178#0: *1 http script regex end
>2008/07/19 14:24:02 [debug] 32178#0: *1 post rewrite phase: 3
>2008/07/19 14:24:02 [debug] 32178#0: *1 uri changes: 10
>2008/07/19 14:24:02 [debug] 32178#0: *1 test location: "/"
>2008/07/19 14:24:02 [debug] 32178#0: *1 test location: "fallback/"
>2008/07/19 14:24:02 [debug] 32178#0: *1 test location: "/dynamic/"
>2008/07/19 14:24:02 [debug] 32178#0: *1 using configuration "/"
>2008/07/19 14:24:02 [debug] 32178#0: *1 http cl:-1 max:1048576
>2008/07/19 14:24:02 [debug] 32178#0: *1 generic phase: 2
>
>It should not recheck the locations...
It should with 'last' flag in rewrite, and shouldn't with 'break'
flag. The default is 'last', and since you haven't specified
'break' in your config - it should.
Solution is obvious:
- rewrite ^/fallback(.*)$ $1;
+ rewrite ^/fallback(.*)$ $1 break;
See http://wiki.codemongers.com/NginxHttpRewriteModule#rewrite for
details.
And, BTW, I think you should use named locations instead. Just
write something like:
location / {
error_page 404 = @fallback;
...
}
location @fallback {
proxy_pass ...;
...
}
You don't actually need all this rewrite stuff. :)
Maxim Dounin
More information about the nginx
mailing list