break flag in rewrite directive

Maxim Dounin mdounin at
Sun Jul 27 16:54:01 UTC 2014


On Sun, Jul 27, 2014 at 07:37:01AM -0400, husseingalal wrote:

> Hi,
> I wanted to ask about break flag in rewrite directive as i understand Nginx
> does not initiate a new request for the modified URI but i cant understand
> how this will be useful?

There is an example in docs,

    location /download/ {
        rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
        rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra  break;
        return  403;

The "break" flag is used here to change an URI, but keep 
processing in the already matched location.  For example, a 
request to "/download/foo/media/bar.mp3" will be mapped to the 
"/root/download/foo/mp3/bar.mp3" file, where "/root" is the 
document root in the "/download/" location.

Maxim Dounin

More information about the nginx mailing list