|
8 | 8 | This module is under active development and is production ready.
|
9 | 9 |
|
10 | 10 | Version
|
11 |
| - This document describes ngx_lua v0.5.1 |
12 |
| - (<https://github.com/chaoslawful/lua-nginx-module/tags>) released on 16 |
| 11 | + This document describes ngx_lua v0.5.2 |
| 12 | + (<https://github.com/chaoslawful/lua-nginx-module/tags>) released on 18 |
13 | 13 | June 2012.
|
14 | 14 |
|
15 | 15 | Synopsis
|
@@ -227,9 +227,9 @@ Directives
|
227 | 227 | to to reload the config file are to send a "HUP" signal or to restart
|
228 | 228 | Nginx.
|
229 | 229 |
|
230 |
| - The ngx_lua module does not currently support the "stat" mode available |
231 |
| - with the Apache "mod_lua" module but this is planned for implementation |
232 |
| - in the future. |
| 230 | + The "ngx_lua" module does not currently support the "stat" mode |
| 231 | + available with the Apache "mod_lua" module but this is planned for |
| 232 | + implementation in the future. |
233 | 233 |
|
234 | 234 | Disabling the Lua code cache is strongly discouraged for production use
|
235 | 235 | and should only be used during development as it has a significant
|
@@ -385,6 +385,10 @@ Directives
|
385 | 385 | can be temporarily disabled during development by switching
|
386 | 386 | lua_code_cache "off" in "nginx.conf" to avoid reloading Nginx.
|
387 | 387 |
|
| 388 | + Since the "v0.5.0rc32" release, the file specified by |
| 389 | + "<path-to-lua-script-file>" can be a pre-compiled Lua/LuaJIT bytecode |
| 390 | + file. |
| 391 | + |
388 | 392 | This directive requires the ngx_devel_kit
|
389 | 393 | (<https://github.com/simpl/ngx_devel_kit>) module.
|
390 | 394 |
|
@@ -428,6 +432,10 @@ Directives
|
428 | 432 | can be temporarily disabled during development by switching
|
429 | 433 | lua_code_cache "off" in "nginx.conf" to avoid reloading Nginx.
|
430 | 434 |
|
| 435 | + Since the "v0.5.0rc32" release, the file specified by |
| 436 | + "<path-to-lua-script-file>" can be a pre-compiled Lua/LuaJIT bytecode |
| 437 | + file. |
| 438 | + |
431 | 439 | rewrite_by_lua
|
432 | 440 | syntax: *rewrite_by_lua <lua-script-str>*
|
433 | 441 |
|
@@ -578,6 +586,10 @@ Directives
|
578 | 586 | "rewrite" request-processing phase unless rewrite_by_lua_no_postpone is
|
579 | 587 | turned on.
|
580 | 588 |
|
| 589 | + Since the "v0.5.0rc32" release, the file specified by |
| 590 | + "<path-to-lua-script-file>" can be a pre-compiled Lua/LuaJIT bytecode |
| 591 | + file. |
| 592 | + |
581 | 593 | access_by_lua
|
582 | 594 | syntax: *access_by_lua <lua-script-str>*
|
583 | 595 |
|
@@ -677,6 +689,10 @@ Directives
|
677 | 689 | lua_code_cache "off" in "nginx.conf" to avoid repeatedly reloading
|
678 | 690 | Nginx.
|
679 | 691 |
|
| 692 | + Since the "v0.5.0rc32" release, the file specified by |
| 693 | + "<path-to-lua-script-file>" can be a pre-compiled Lua/LuaJIT bytecode |
| 694 | + file. |
| 695 | + |
680 | 696 | header_filter_by_lua
|
681 | 697 | syntax: *header_filter_by_lua <lua-script-str>*
|
682 | 698 |
|
@@ -723,6 +739,10 @@ Directives
|
723 | 739 | into the absolute path relative to the "server prefix" path determined
|
724 | 740 | by the "-p PATH" command-line option while starting the Nginx server.
|
725 | 741 |
|
| 742 | + Since the "v0.5.0rc32" release, the file specified by |
| 743 | + "<path-to-lua-script-file>" can be a pre-compiled Lua/LuaJIT bytecode |
| 744 | + file. |
| 745 | + |
726 | 746 | This directive was first introduced in the "v0.2.1rc20" release.
|
727 | 747 |
|
728 | 748 | body_filter_by_lua
|
@@ -831,6 +851,10 @@ Directives
|
831 | 851 | into the absolute path relative to the "server prefix" path determined
|
832 | 852 | by the "-p PATH" command-line option while starting the Nginx server.
|
833 | 853 |
|
| 854 | + Since the "v0.5.0rc32" release, the file specified by |
| 855 | + "<path-to-lua-script-file>" can be a pre-compiled Lua/LuaJIT bytecode |
| 856 | + file. |
| 857 | + |
834 | 858 | This directive was first introduced in the "v0.5.0rc32" release.
|
835 | 859 |
|
836 | 860 | log_by_lua
|
@@ -913,6 +937,10 @@ Directives
|
913 | 937 | into the absolute path relative to the "server prefix" path determined
|
914 | 938 | by the "-p PATH" command-line option while starting the Nginx server.
|
915 | 939 |
|
| 940 | + Since the "v0.5.0rc32" release, the file specified by |
| 941 | + "<path-to-lua-script-file>" can be a pre-compiled Lua/LuaJIT bytecode |
| 942 | + file. |
| 943 | + |
916 | 944 | This directive was first introduced in the "v0.5.0rc31" release.
|
917 | 945 |
|
918 | 946 | lua_need_request_body
|
@@ -2502,7 +2530,7 @@ Nginx API for Lua
|
2502 | 2530 | ngx.exec("/foo", "a=3&b=hello%20world")
|
2503 | 2531 |
|
2504 | 2532 | Alternatively, a Lua table can be passed for the "args" argument for
|
2505 |
| - ngx_lua to carry out URI escaping and string concatenation |
| 2533 | + "ngx_lua" to carry out URI escaping and string concatenation |
2506 | 2534 | automatically.
|
2507 | 2535 |
|
2508 | 2536 | ngx.exec("/foo", { a = 3, b = "hello world" })
|
@@ -2596,10 +2624,10 @@ Nginx API for Lua
|
2596 | 2624 |
|
2597 | 2625 | context: *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua**
|
2598 | 2626 |
|
2599 |
| - Returns "true" if the response headers have been sent (by ngx_lua), and |
2600 |
| - "false" otherwise. |
| 2627 | + Returns "true" if the response headers have been sent (by "ngx_lua"), |
| 2628 | + and "false" otherwise. |
2601 | 2629 |
|
2602 |
| - This API was first introduced in ngx_lua v0.3.1rc6. |
| 2630 | + This API was first introduced in "ngx_lua" v0.3.1rc6. |
2603 | 2631 |
|
2604 | 2632 | ngx.print
|
2605 | 2633 | syntax: *ngx.print(...)*
|
@@ -4101,44 +4129,44 @@ Nginx API for Lua
|
4101 | 4129 | (<https://github.com/simpl/ngx_devel_kit>) module.
|
4102 | 4130 |
|
4103 | 4131 | Lua/LuaJIT bytecode support
|
4104 |
| - Since the "v0.5.0rc32" release, all the *_by_lua_file configure |
4105 |
| - directives (like content_by_lua_file) support loading Lua 5.1 and LuaJIT |
4106 |
| - 2.0 raw bytecode files automatically. |
| 4132 | + All *_by_lua_file configure directives (such as content_by_lua_file) |
| 4133 | + support directly loading Lua 5.1 and LuaJIT 2.0 raw bytecode files since |
| 4134 | + the "v0.5.0rc32" release. |
4107 | 4135 |
|
4108 |
| - Please note that the bytecode format used by LuaJIT 2.0 is completely |
4109 |
| - different from the standard Lua 5.1 interpreter's. So if you're using |
4110 |
| - LuaJIT 2.0 with this Nginx module, you need to use LuaJIT 2.0 to |
4111 |
| - generate LuaJIT-compatible bytecode files, like this: |
| 4136 | + Please note that the bytecode format used by LuaJIT 2.0 is not |
| 4137 | + compatible with that for the standard Lua 5.1 interpreter. So if using |
| 4138 | + LuaJIT 2.0 with "ngx_lua", LuaJIT-compatible bytecode files must be |
| 4139 | + generated as shown: |
4112 | 4140 |
|
4113 |
| - /path/to/luajit/bin/luajit-2.0.0-beta10 -b /path/to/your.lua /path/to/your.luac |
| 4141 | + /path/to/luajit/bin/luajit -b /path/to/input_file.lua /path/to/output_file.luac |
4114 | 4142 |
|
4115 |
| - You can use the "-bg" option instead to include debug information in the |
4116 |
| - LuaJIT bytecode file: |
| 4143 | + The "-bg" option can be used to include debug information in the LuaJIT |
| 4144 | + bytecode file: |
4117 | 4145 |
|
4118 |
| - /path/to/luajit/bin/luajit-2.0.0-beta10 -bg /path/to/your.lua /path/to/your.luac |
| 4146 | + /path/to/luajit/bin/luajit -bg /path/to/input_file.lua /path/to/output_file.luac |
4119 | 4147 |
|
4120 |
| - Check out the official documentation for "luajit"'s "-b" option for more |
4121 |
| - details: |
| 4148 | + Please refer to the official LuaJIT documentation for the "-b" option |
| 4149 | + for more details: |
4122 | 4150 |
|
4123 | 4151 | http://luajit.org/running.html#opt_b
|
4124 | 4152 |
|
4125 |
| - Similarly, if you're using the standard Lua 5.1 interpreter with this |
4126 |
| - Nginx module, then you need to use the "luac" command-line utility to |
4127 |
| - generate the Lua-compatible bytecode files, like this: |
| 4153 | + Similarly, if using the standard Lua 5.1 interpreter with "ngx_lua", |
| 4154 | + Lua-compatible bytecode files must be generated using the "luac" |
| 4155 | + command-line utility as shown: |
4128 | 4156 |
|
4129 |
| - luac -o /path/to/your.luac /path/to/your.lua |
| 4157 | + luac -o /path/to/output_file.luac /path/to/input_file.lua |
4130 | 4158 |
|
4131 |
| - Unlike LuaJIT, the debug information in included in standard Lua 5.1's |
4132 |
| - bytecode by default. You can strip the debug information by specifying |
4133 |
| - the "-s" option, as in |
| 4159 | + Unlike as with LuaJIT, debug information is included in standard Lua 5.1 |
| 4160 | + bytecode files by default. This can be striped out by specifying the |
| 4161 | + "-s" option as shown: |
4134 | 4162 |
|
4135 |
| - luac -s -o /path/to/your.luac /path/to/your.lua |
| 4163 | + luac -s -o /path/to/output_file.luac /path/to/input_file.lua |
4136 | 4164 |
|
4137 |
| - If you're trying to load a standard Lua 5.1 bytecode file into an nginx |
4138 |
| - linked with LuaJIT 2.0 or in the other way around, you will get an error |
4139 |
| - message like below in your Nginx's "error.log" file: |
| 4165 | + Attempts to load standard Lua 5.1 bytecode files into "ngx_lua" |
| 4166 | + instances linked to LuaJIT 2.0 or vice versa, an error message such as |
| 4167 | + that below will be logged in the Nginx "error.log" file: |
4140 | 4168 |
|
4141 |
| - [error] 13909\#0: *1 failed to load Lua inlined code: bad byte-code header in /path/to/test.luac |
| 4169 | + [error] 13909#0: *1 failed to load Lua inlined code: bad byte-code header in /path/to/test_file.luac |
4142 | 4170 |
|
4143 | 4171 | Loading bytecode files via the Lua primitives like "require" and
|
4144 | 4172 | "dofile" should always work as expected.
|
@@ -4250,16 +4278,16 @@ Known Issues
|
4250 | 4278 | 5.1 and LuaJIT 2.0 and when ngx.location.capture is called,
|
4251 | 4279 | ngx.exec, ngx.exit or ngx.req.read_body or similar in the file to be
|
4252 | 4280 | loaded by "dofile", a coroutine yield across the C function boundary
|
4253 |
| - will be initiated. This however is not allowed within ngx_lua and |
4254 |
| - will usually result in error messages like "lua handler aborted: |
4255 |
| - runtime error: attempt to yield across C-call boundary". To avoid |
4256 |
| - this, define a real Lua module and use the Lua "require" builtin |
4257 |
| - instead. |
4258 |
| - |
4259 |
| - * Because the standard Lua 5.1 interpreter's VM is not fully |
4260 |
| - resumable, the methods ngx.location.capture, |
4261 |
| - ngx.location.capture_multi, ngx.redirect, ngx.exec, and ngx.exit |
4262 |
| - cannot be used within the context of a Lua pcall() |
| 4281 | + will be initiated. This however is not normally allowed within |
| 4282 | + "ngx_lua" and will usually result in error messages like "lua |
| 4283 | + handler aborted: runtime error: attempt to yield across C-call |
| 4284 | + boundary". To avoid this, define a real Lua module and use the Lua |
| 4285 | + "require" builtin instead. |
| 4286 | + |
| 4287 | + * As the standard Lua 5.1 interpreter's VM is not fully resumable, the |
| 4288 | + methods ngx.location.capture, ngx.location.capture_multi, |
| 4289 | + ngx.redirect, ngx.exec, and ngx.exit cannot be used within the |
| 4290 | + context of a Lua pcall() |
4263 | 4291 | (<http://www.lua.org/manual/5.1/manual.html#pdf-pcall>) or xpcall()
|
4264 | 4292 | (<http://www.lua.org/manual/5.1/manual.html#pdf-xpcall>) when the
|
4265 | 4293 | standard Lua 5.1 interpreter is used and the "attempt to yield
|
@@ -4460,6 +4488,9 @@ Typical Uses
|
4460 | 4488 | Nginx Compatibility
|
4461 | 4489 | The module is compatible with the following versions of Nginx:
|
4462 | 4490 |
|
| 4491 | + * |
| 4492 | + 1.2.x (last tested: 1.2.1) |
| 4493 | + |
4463 | 4494 | *
|
4464 | 4495 | 1.1.x (last tested: 1.1.5)
|
4465 | 4496 |
|
@@ -4495,7 +4526,7 @@ Installation
|
4495 | 4526 | 2. Download the latest version of the ngx_devel_kit (NDK) module HERE
|
4496 | 4527 | (<http://github.com/simpl/ngx_devel_kit/tags>).
|
4497 | 4528 |
|
4498 |
| - 3. Download the latest version of this module HERE |
| 4529 | + 3. Download the latest version of "ngx_lua" HERE |
4499 | 4530 | (<http://github.com/chaoslawful/lua-nginx-module/tags>).
|
4500 | 4531 |
|
4501 | 4532 | 4. Download the latest version of Nginx HERE (<http://nginx.org/>) (See
|
@@ -4595,7 +4626,7 @@ Changes
|
4595 | 4626 |
|
4596 | 4627 | * bugfix: ngx.exit, ngx.redirect, ngx.exec, and ngx.req.set_uri(uri,
|
4597 | 4628 | true) could return (they should never return as per the
|
4598 |
| - documentation). this bug had appeared in ngx_lua v0.3.1rc4 and |
| 4629 | + documentation). this bug had appeared in "ngx_lua" v0.3.1rc4 and |
4599 | 4630 | ngx_openresty 1.0.6.13. thanks @cyberty (<http://weibo.com/cyberty>)
|
4600 | 4631 | for reporting it.
|
4601 | 4632 |
|
@@ -4637,7 +4668,7 @@ Changes
|
4637 | 4668 | value. thanks sexybabes.
|
4638 | 4669 |
|
4639 | 4670 | * feature: implemented the ngx.headers_sent API to check if response
|
4640 |
| - headers are sent (by ngx_lua). thanks @hugozhu. |
| 4671 | + headers are sent (by "ngx_lua"). thanks @hugozhu. |
4641 | 4672 |
|
4642 | 4673 | * feature: exposes the CRC-32 API of the Nginx core to the Lua land,
|
4643 | 4674 | in the form of the ngx.crc32_short and ngx.crc32_long methods.
|
|
0 commit comments