0

This question is an extension of rewrite break vs last. From what I understand the break statement will stop processing the current set of rewrite statements and instead of triggering a new location search, it would continue processing the rest of the statements in the current location block. If this is the case, what is the purpose of the replacement url given in the rewrite directive.

2
  • That will be value of $uri variable. It's used in proxy, fastcgi and some other things.
    – Alexey Ten
    Oct 31, 2014 at 10:54
  • nginx.org/r/proxy_pass there is example with rewrite
    – Alexey Ten
    Oct 31, 2014 at 10:56

1 Answer 1

1

If a matching rewrite rule is found a new URI is being composed using the specified rule.

With break keyword nginx uses the new URI within the location block rewrite was in.

So if there is nothing else in current location nginx will try to serve a file using a new URI. If you have a proxy_pass or something like that then it will forward a request with a new URI.

If last keyword is specified then after creating a new URI nginx "restarts" the process of request handling and triggers a new search over location blocks but new URI.

last and break are well documented in nginx documentation:

last stops processing the current set of ngx_http_rewrite_module directives and starts a search for a new location matching the changed URI;

break stops processing the current set of ngx_http_rewrite_module directives as with the break directive;

If rewrite rule appears in a server block then it seems that there is no difference between last and break.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .