documented that rewrite phase Lua code will be skipped if location re-lookup is triggered by the standard ngx_rewrite module's rewrite directive. thanks Nginx User.

This commit is contained in:
agentzh (章亦春) 2011-10-16 10:07:50 +08:00
Родитель 95faaaa2d4
Коммит f72eb473cb
3 изменённых файлов: 73 добавлений и 9 удалений

30
README
Просмотреть файл

@ -8,7 +8,7 @@ Status
This module is under active development and is already production ready.
Version
This document describes ngx_lua v0.3.1rc12
This document describes ngx_lua v0.3.1rc13
(<https://github.com/chaoslawful/lua-nginx-module/tags>) released on 16
October 2011.
@ -482,6 +482,26 @@ Directives
"ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)" (or its friends) for
failures.
If one uses [[HttpRewriteModule]]'s rewrite directive to change the URI
and initiate location re-lookups (kinda like internal redirections),
then rewrite_by_lua and rewrite_by_lua_file will be skipped altogether
in the current location. For example,
location /foo {
rewrite ^ /bar;
rewrite_by_lua 'ngx.exit(503)';
}
location /bar {
...
}
Here the Lua code "ngx.exit(503)" will never run while all the Lua code
(except access phase handlers) in the "/bar" location will not be
affected anyway. Similarly, "rewrite ^ /bar last" will also initiate a
location re-lookup. If you use the "break" modifier for the rewrite
directive, however, no location re-lookup will be triggered, and
therefore, the rewrite-phase Lua code will still be run as normal.
rewrite_by_lua_file
syntax: *rewrite_by_lua_file <path-to-lua-script>*
@ -1264,7 +1284,7 @@ Nginx API for Lua
modifier in the standard [[HttpRewriteModule]], for example, this
"nginx.conf" snippet
rewrite ^ /foo redirect; # nginx config
rewrite ^ /foo? redirect; # nginx config
is equivalent to the following Lua code
@ -1272,12 +1292,16 @@ Nginx API for Lua
while
rewrite ^ /foo permanent; # nginx config
rewrite ^ /foo? permanent; # nginx config
is equivalent to
return ngx.redirect('/foo', ngx.HTTP_MOVED_PERMANENTLY) -- Lua code
URI arguments can be specified as well, for example:
return ngx.redirect('/foo?a=3&b=4')
ngx.send_headers
syntax: *ngx.send_headers()*

Просмотреть файл

@ -13,7 +13,7 @@ This module is under active development and is already production ready.
Version
=======
This document describes ngx_lua [v0.3.1rc12](https://github.com/chaoslawful/lua-nginx-module/tags) released on 16 October 2011.
This document describes ngx_lua [v0.3.1rc13](https://github.com/chaoslawful/lua-nginx-module/tags) released on 16 October 2011.
Synopsis
========
@ -490,6 +490,20 @@ Just as any other rewrite phase handlers, [rewrite_by_lua](http://wiki.nginx.org
Note that calling `ngx.exit(ngx.OK)` just returning from the current [rewrite_by_lua](http://wiki.nginx.org/HttpLuaModule#rewrite_by_lua) handler, and the nginx request processing control flow will still continue to the content handler. To terminate the current request from within the current [rewrite_by_lua](http://wiki.nginx.org/HttpLuaModule#rewrite_by_lua) handler, calling [ngx.exit](http://wiki.nginx.org/HttpLuaModule#ngx.exit) with status >= 200 (`ngx.HTTP_OK`) and status < 300 (`ngx.HTTP_SPECIAL_RESPONSE`) for successful quits and `ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)` (or its friends) for failures.
If one uses [HttpRewriteModule](http://wiki.nginx.org/HttpRewriteModule)'s [rewrite](http://wiki.nginx.org/HttpRewriteModule#rewrite) directive to change the URI and initiate location re-lookups (kinda like internal redirections), then [rewrite_by_lua](http://wiki.nginx.org/HttpLuaModule#rewrite_by_lua) and [rewrite_by_lua_file](http://wiki.nginx.org/HttpLuaModule#rewrite_by_lua_file) will be skipped altogether in the current location. For example,
location /foo {
rewrite ^ /bar;
rewrite_by_lua 'ngx.exit(503)';
}
location /bar {
...
}
Here the Lua code `ngx.exit(503)` will never run while all the Lua code (except access phase handlers) in the `/bar` location will not be affected anyway. Similarly, `rewrite ^ /bar last` will also initiate a location re-lookup. If you use the `break` modifier for the [rewrite](http://wiki.nginx.org/HttpRewriteModule#rewrite) directive, however, no location re-lookup will be triggered, and therefore, the rewrite-phase Lua code will still be run as normal.
rewrite_by_lua_file
-------------------
@ -1449,7 +1463,7 @@ This method is very much like the [rewrite](http://wiki.nginx.org/HttpRewriteMod
[HttpRewriteModule](http://wiki.nginx.org/HttpRewriteModule), for example, this `nginx.conf` snippet
rewrite ^ /foo redirect; # nginx config
rewrite ^ /foo? redirect; # nginx config
is equivalent to the following Lua code
@ -1461,7 +1475,7 @@ is equivalent to the following Lua code
while
rewrite ^ /foo permanent; # nginx config
rewrite ^ /foo? permanent; # nginx config
is equivalent to
@ -1470,6 +1484,12 @@ is equivalent to
return ngx.redirect('/foo', ngx.HTTP_MOVED_PERMANENTLY) -- Lua code
URI arguments can be specified as well, for example:
return ngx.redirect('/foo?a=3&b=4')
ngx.send_headers
----------------
**syntax:** *ngx.send_headers()*

Просмотреть файл

@ -10,7 +10,7 @@ This module is under active development and is already production ready.
= Version =
This document describes ngx_lua [https://github.com/chaoslawful/lua-nginx-module/tags v0.3.1rc12] released on 16 October 2011.
This document describes ngx_lua [https://github.com/chaoslawful/lua-nginx-module/tags v0.3.1rc13] released on 16 October 2011.
= Synopsis =
<geshi lang="nginx">
@ -475,6 +475,20 @@ Just as any other rewrite phase handlers, [[#rewrite_by_lua|rewrite_by_lua]] als
Note that calling <code>ngx.exit(ngx.OK)</code> just returning from the current [[#rewrite_by_lua|rewrite_by_lua]] handler, and the nginx request processing control flow will still continue to the content handler. To terminate the current request from within the current [[#rewrite_by_lua|rewrite_by_lua]] handler, calling [[#ngx.exit|ngx.exit]] with status >= 200 (<code>ngx.HTTP_OK</code>) and status < 300 (<code>ngx.HTTP_SPECIAL_RESPONSE</code>) for successful quits and <code>ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)</code> (or its friends) for failures.
If one uses [[HttpRewriteModule]]'s [[HttpRewriteModule#rewrite|rewrite]] directive to change the URI and initiate location re-lookups (kinda like internal redirections), then [[#rewrite_by_lua|rewrite_by_lua]] and [[#rewrite_by_lua_file|rewrite_by_lua_file]] will be skipped altogether in the current location. For example,
<geshi lang="nginx">
location /foo {
rewrite ^ /bar;
rewrite_by_lua 'ngx.exit(503)';
}
location /bar {
...
}
</geshi>
Here the Lua code <code>ngx.exit(503)</code> will never run while all the Lua code (except access phase handlers) in the <code>/bar</code> location will not be affected anyway. Similarly, <code>rewrite ^ /bar last</code> will also initiate a location re-lookup. If you use the <code>break</code> modifier for the [[HttpRewriteModule#rewrite|rewrite]] directive, however, no location re-lookup will be triggered, and therefore, the rewrite-phase Lua code will still be run as normal.
== rewrite_by_lua_file ==
'''syntax:''' ''rewrite_by_lua_file <path-to-lua-script>''
@ -1408,7 +1422,7 @@ This method is very much like the [[HttpRewriteModule#rewrite|rewrite]] directiv
[[HttpRewriteModule]], for example, this <code>nginx.conf</code> snippet
<geshi lang="nginx">
rewrite ^ /foo redirect; # nginx config
rewrite ^ /foo? redirect; # nginx config
</geshi>
is equivalent to the following Lua code
@ -1420,7 +1434,7 @@ is equivalent to the following Lua code
while
<geshi lang="nginx">
rewrite ^ /foo permanent; # nginx config
rewrite ^ /foo? permanent; # nginx config
</geshi>
is equivalent to
@ -1429,6 +1443,12 @@ is equivalent to
return ngx.redirect('/foo', ngx.HTTP_MOVED_PERMANENTLY) -- Lua code
</geshi>
URI arguments can be specified as well, for example:
<geshi lang="lua">
return ngx.redirect('/foo?a=3&b=4')
</geshi>
== ngx.send_headers ==
'''syntax:''' ''ngx.send_headers()''