413
481
ngx.redirect("/terms-of-use.html")
417
485
fastcgi_pass ...;
420
Just as any other rewrite-phase handlers, `rewrite_by_lua` also runs in subrequests.
422
Note that calling `ngx.exit(ngx.OK)` just returning from the current `rewrite_by_lua` handler, and the nginx request processing
423
control flow will still continue to the content handler. To terminate the current request from within the current `rewrite_by_lua` handler,
424
calling `ngx.exit(ngx.HTTP_OK)` for successful quits and `ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)` or its friends for failures.
489
Just as any other rewrite phase handlers, [rewrite_by_lua](http://wiki.nginx.org/HttpLuaModule#rewrite_by_lua) also runs in subrequests.
491
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.
496
**syntax:** *rewrite_by_lua_file <path-to-lua-script>*
498
**context:** *http, server, location, location if*
500
**phase:** *rewrite tail*
502
Same as [rewrite_by_lua](http://wiki.nginx.org/HttpLuaModule#rewrite_by_lua), except the code to be executed is in
503
the file specified by `<path-lua-script>`.
505
Nginx variables can be used in `<path-to-lua-script>` string, in order to provide
506
greater flexibility in practice. But this feature must be used carefully, so is
507
not recommend for beginners.
509
When the Lua code cache is on (this is the default), the user code is loaded
510
once at the first request and cached. Nginx config must be reloaded if you
511
modified the file and expected to see updated behavior. You can disable the
512
Lua code cache by setting [lua_code_cache](http://wiki.nginx.org/HttpLuaModule#lua_code_cache) `off` in your `nginx.conf` file.
429
* **Syntax:** `access_by_lua <lua-script-str>`
430
* **Context:** `http`, `server`, `location`, `location if`
431
* **Phase:** `access tail`
433
Act as an access phase handler and execute user code specified by `<lua-script-str>`
434
for every request. The user code may call predefined APIs to generate response
437
This hook uses exactly the same mechamism as `content_by_lua`
438
so all the nginx APIs defined there
439
are also available here.
441
Note that this handler always runs *after* the standard nginx
442
access module ( http://wiki.nginx.org/NginxHttpAccessModule ).
443
So the following will work as expected:
517
**syntax:** *access_by_lua <lua-script-str>*
519
**context:** *http, server, location, location if*
521
**phase:** *access tail*
523
Act as an access phase handler and execute user code specified by `<lua-script-str>` for every request. The user code may call predefined APIs to generate response content.
525
This hook uses exactly the same mechanism as [content_by_lua](http://wiki.nginx.org/HttpLuaModule#content_by_lua) so all the nginx APIs defined there are also available here.
527
Note that this handler always runs *after* the standard [HttpAccessModule](http://wiki.nginx.org/HttpAccessModule). So the following will work as expected:
446
531
deny 192.168.1.1;
447
532
allow 192.168.1.0/24;
448
533
allow 10.1.1.0/16;
452
537
local res = ngx.location.capture("/mysql", { ... })
456
541
# proxy_pass/fastcgi_pass/...
459
That is, if a client address appears in the blacklist, then
460
we don't have to bother sending a mysql query to do more
461
advanced authentication in `access_by_lua`.
463
It's worth mentioning that, the `ngx_auth_request` module can be
464
approximately implemented by `access_by_lua`. For example,
545
That is, if a client address appears in the blacklist, then we don't have to bother sending a MySQL query to do more advanced authentication in [access_by_lua](http://wiki.nginx.org/HttpLuaModule#access_by_lua).
547
It's worth mentioning that, the `ngx_auth_request` module can be approximately implemented by [access_by_lua](http://wiki.nginx.org/HttpLuaModule#access_by_lua). For example,
467
551
auth_request /auth;
469
553
# proxy_pass/fastcgi_pass/postgres_pass/...
472
557
can be implemented in terms of `ngx_lua` like this
476
562
local res = ngx.location.capture("/auth")
478
564
if res.status == ngx.HTTP_OK then
482
568
if res.status == ngx.HTTP_FORBIDDEN then
483
569
ngx.exit(res.status)
486
572
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
489
575
# proxy_pass/fastcgi_pass/postgres_pass/...
492
Just as any other access-phase handlers, `access_by_lua` will NOT run in subrequests.
494
Note that calling `ngx.exit(ngx.OK)` just returning from the current `access_by_lua` handler, and the nginx request processing
495
control flow will still continue to the content handler. To terminate the current request from within the current `access_by_lua` handler,
496
calling `ngx.exit(ngx.HTTP_OK)` for successful quits and `ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)` or its friends for failures.
501
* **Syntax:** `content_by_lua_file <path-to-lua-script>`
502
* **Context:** `location`, `location if`
503
* **Phase:** `content`
505
Basically the same as `content_by_lua`, except the code to be executed is in
506
the file specified by `<path-lua-script>`.
508
Nginx variables can be used in <path-to-lua-script> string, in order to provide
509
greater flexibility in practice. But this feature must be used carefully, so is
510
not recommend for beginners.
512
When the Lua code cache is on (this is the default), the user code is loaded
513
once at the first request and cached. Nginx config must be reloaded if you
514
modified the file and expected to see updated behavior. You can disable the
515
Lua code cache by setting `lua_code_cache off;` in your nginx.conf.
520
* **Syntax:** `rewrite_by_lua_file <path-to-lua-script>`
521
* **Context:** `http`, `server`, `location`, `location if`
522
* **Phase:** `rewrite tail`
524
Same as `rewrite_by_lua`, except the code to be executed is in
525
the file specified by `<path-lua-script>`.
527
Nginx variables can be used in <path-to-lua-script> string, in order to provide
528
greater flexibility in practice. But this feature must be used carefully, so is
529
not recommend for beginners.
531
When the Lua code cache is on (this is the default), the user code is loaded
532
once at the first request and cached. Nginx config must be reloaded if you
533
modified the file and expected to see updated behavior. You can disable the
534
Lua code cache by setting `lua_code_cache off;` in your nginx.conf.
579
Just as any other access phase handlers, [access_by_lua](http://wiki.nginx.org/HttpLuaModule#access_by_lua) will *not* run in subrequests.
581
Note that calling `ngx.exit(ngx.OK)` just returning from the current [access_by_lua](http://wiki.nginx.org/HttpLuaModule#access_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 [access_by_lua](http://wiki.nginx.org/HttpLuaModule#access_by_lua) handler, calling `ngx.exit(status)` where 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.
536
583
access_by_lua_file
539
* **Syntax:** `access_by_lua_file <path-to-lua-script>`
540
* **Context:** `http`, `server`, `location`, `location if`
541
* **Phase:** `access tail`
543
Same as `access_by_lua`, except the code to be executed is in the file
586
**syntax:** *access_by_lua_file <path-to-lua-script>*
588
**context:** *http, server, location, location if*
590
**phase:** *access tail*
592
Same as [access_by_lua](http://wiki.nginx.org/HttpLuaModule#access_by_lua), except the code to be executed is in the file
544
593
specified by `<path-lua-script>`.
546
Nginx variables can be used in <path-to-lua-script> string, in order to provide
595
Nginx variables can be used in `<path-to-lua-script>` string, in order to provide
547
596
greater flexibility in practice. But this feature must be used carefully, so is
548
597
not recommend for beginners.
550
599
When the Lua code cache is on (this is the default), the user code is loaded
551
600
once at the first request and cached. Nginx config must be reloaded if you
552
601
modified the file and expected to see updated behavior. You can disable the
553
Lua code cache by setting `lua_code_cache off;` in your nginx.conf.
602
Lua code cache by setting [lua_code_cache](http://wiki.nginx.org/HttpLuaModule#lua_code_cache) `off` in your `nginx.conf` file.
607
**syntax:** *header_filter_by_lua <lua-script-str>*
609
**context:** *http, server, location, location if*
611
**phase:** *output header filter*
613
Use Lua defined in `<lua-script-str>` to define an output header filter. For now, the following Nginx Lua APIs are disabled in this context:
615
* Output API (e.g., [ngx.say](http://wiki.nginx.org/HttpLuaModule#ngx.say) and [ngx.send_headers](http://wiki.nginx.org/HttpLuaModule#ngx.send_headers))
616
* Control APIs (e.g., [ngx.exit](http://wiki.nginx.org/HttpLuaModule#ngx.exit))
617
* Subrequest APIs (e.g., [ngx.location.capture](http://wiki.nginx.org/HttpLuaModule#ngx.location.capture) and [ngx.location.capture_multi](http://wiki.nginx.org/HttpLuaModule#ngx.location.capture_multi))
619
Here's a small example of overriding a response header (or adding if it does not exist) in our Lua header filter:
622
proxy_pass http://mybackend;
623
header_filter_by_lua 'ngx.header.Foo = "blah"';
627
This directive was first introduced in the `v0.2.1rc20` release.
629
header_filter_by_lua_file
630
-------------------------
632
**syntax:** *header_filter_by_lua_file <path-to-lua-script-file>*
634
**context:** *http, server, location, location if*
636
**phase:** *output header filter*
638
Use Lua code defined in a separate file specified by `<path-to-lua-script-file>` to define an output header filter.
640
This is very much like [header_filter_by_lua](http://wiki.nginx.org/HttpLuaModule#header_filter_by_lua) except that it loads Lua code from an external Lua source file.
642
This directive was first introduced in the `v0.2.1rc20` release.
555
644
lua_need_request_body
556
645
---------------------
558
* **Syntax:** `lua_need_request_body <on | off>`
560
* **Context:** `main | server | location`
561
* **Phase:** `depends on usage`
563
Force reading request body data or not. The client request body won't be read,
564
so you have to explicitly force reading the body if you need its content.
566
If you want to read the request body data from the `$request_body` variable, make sure that
567
your set `client_body_in_single_buffer` on. See
569
<http://wiki.nginx.org/NginxHttpCoreModule#client_body_in_single_buffer>
573
If the current location defines `rewrite_by_lua` or `rewrite_by_lua_file`,
574
then the request body will be read just before the `rewrite_by_lua` or `rewrite_by_lua_file` code is run (and also at the
575
`rewrite` phase). Similarly, if only `content_by_lua` is specified,
647
**syntax:** *lua_need_request_body <on | off>*
651
**context:** *main | server | location*
653
**phase:** *depends on usage*
655
Force reading request body data or not. The client request body won't be read, so you have to explicitly force reading the body if you need its content.
657
If you want to read the request body data from the [$request_body](http://wiki.nginx.org/HttpCoreModule#.24request_body) variable, make sure that
658
your have configured [client_body_buffer_size](http://wiki.nginx.org/HttpCoreModule#client_body_buffer_size) to have exactly the same value as [client_max_body_size](http://wiki.nginx.org/HttpCoreModule#client_max_body_size).
660
If the current location defines [rewrite_by_lua](http://wiki.nginx.org/HttpLuaModule#rewrite_by_lua) or [rewrite_by_lua_file](http://wiki.nginx.org/HttpLuaModule#rewrite_by_lua_file),
661
then the request body will be read just before the [rewrite_by_lua](http://wiki.nginx.org/HttpLuaModule#rewrite_by_lua) or [rewrite_by_lua_file](http://wiki.nginx.org/HttpLuaModule#rewrite_by_lua_file) code is run (and also at the
662
`rewrite` phase). Similarly, if only [content_by_lua](http://wiki.nginx.org/HttpLuaModule#content_by_lua) is specified,
576
663
the request body won't be read until the content handler's Lua code is
577
664
about to run (i.e., the request body will be read at the
580
The same applies to `access_by_lua` and `access_by_lua_file`.
667
The same applies to [access_by_lua](http://wiki.nginx.org/HttpLuaModule#access_by_lua) and [access_by_lua_file](http://wiki.nginx.org/HttpLuaModule#access_by_lua_file).
582
669
Nginx API for Lua
583
670
=================
587
* **Context:** `set_by_lua*`
589
Index the input arguments to the set_by_lua* directives:
672
The Nginx API exposed to the Lua land is provided in the form of two standard packages `ngx` and `ndk`. These packages are in the default global scope.
674
When you're writing your own external Lua modules, however, you can introduce these packages by using the [package.seeall](http://www.lua.org/manual/5.1/manual.html#pdf-package.seeall) option:
677
module("my_module", package.seeall)
679
function say(a) ngx.say(a) end
682
Alternatively, import them to your Lua modules by using file-scoped local Lua variables, like this:
688
function say(a) ngx.say(a) end
691
You can directly require the standard packages `ngx` and `ndk` introduced by this Nginx module, like this:
694
local ngx = require "ngx"
695
local ndk = require "ndk"
698
The ability to require these packages was introduced in the `v0.2.1rc19` release.
700
Network I/O operations in user code should only be done through our Nginx APIs defined below, otherwise Nginx event loop may be blocked and performance may drop off dramatically. Small disk file operations can be done via Lua's standard `io` and `file` libraries but should be eliminated wherever possible because these also block the Nginx process. Delegating all network and disk I/O operations to Nginx subrequests (via the [ngx.location.capture](http://wiki.nginx.org/HttpLuaModule#ngx.location.catpure) method and its friends) are strongly recommended.
704
**syntax:** *val = ngx.arg[index]*
706
**context:** *set_by_lua**
708
Index the input arguments to the [set_by_lua](http://wiki.nginx.org/HttpLuaModule#set_by_lua) and [set_by_lua_file](http://wiki.nginx.org/HttpLuaModule#set_by_lua_file) directives:
591
711
value = ngx.arg[n]
593
714
Here's an example
600
722
'return tonumber(ngx.arg[1]) + tonumber(ngx.arg[2])'
606
that outputs 88, the sum of 32 and 56.
608
Read and write Nginx variables
609
------------------------------
610
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
729
that outputs `88`, the sum of `32` and `56`.
733
**syntax:** *ngx.var.VAR_NAME*
735
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
612
737
value = ngx.var.some_nginx_variable_name
613
738
ngx.var.some_nginx_variable_name = value
626
751
That is, nginx variables cannot be created on-the-fly.
753
Some special nginx variables like `$args` and `$limit_rate` can be assigned a value,
754
some are not, like `$arg_PARAMETER`.
756
Nginx regex group capturing variables `$1`, `$2`, `$3`, and etc, can be read by this
757
interface as well, by writing `ngx.var[1]`, `ngx.var[2]`, `ngx.var[3]`, and etc.
629
---------------------
630
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
637
They take the same values of NGX_OK, NGX_AGAIN, NGX_DONE, NGX_ERROR, and etc. But now
638
only ngx.exit() only take two of these values, i.e., NGX_OK and NGX_ERROR. I'll add a
639
quick note to README. Thanks for reminding us. The return values of the Lua "return"
640
statement will be silently ignored.
761
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
769
They take the same values of `NGX_OK`, `NGX_AGAIN`, `NGX_DONE`, `NGX_ERROR`, and etc. But now
770
only [ngx.exit](http://wiki.nginx.org/HttpLuaModule#ngx.exit) only take two of these values, i.e., `NGX_OK` and `NGX_ERROR`.
642
772
HTTP method constants
643
773
---------------------
644
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
647
value = ngx.HTTP_HEAD
649
value = ngx.HTTP_POST
650
value = ngx.HTTP_DELETE
774
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
784
These constants are usually used in [ngx.location.catpure](http://wiki.nginx.org/HttpLuaModule#ngx.location.capture) and [ngx.location.capture_multi](http://wiki.nginx.org/HttpLuaModule#ngx.location.capture_multi) method calls.
652
786
HTTP status constants
653
787
---------------------
654
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
657
value = ngx.HTTP_CREATED
658
value = ngx.HTTP_MOVED_PERMANENTLY
659
value = ngx.HTTP_MOVED_TEMPORARILY
660
value = ngx.HTTP_NOT_MODIFIED
661
value = ngx.HTTP_BAD_REQUEST
662
value = ngx.HTTP_GONE
663
value = ngx.HTTP_NOT_FOUND
664
value = ngx.HTTP_NOT_ALLOWED
665
value = ngx.HTTP_FORBIDDEN
666
value = ngx.HTTP_INTERNAL_SERVER_ERROR
667
value = ngx.HTTP_SERVICE_UNAVAILABLE
788
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
790
value = ngx.HTTP_OK (200)
791
value = ngx.HTTP_CREATED (201)
792
value = ngx.HTTP_SPECIAL_RESPONSE (300)
793
value = ngx.HTTP_MOVED_PERMANENTLY (301)
794
value = ngx.HTTP_MOVED_TEMPORARILY (302)
795
value = ngx.HTTP_SEE_OTHER (303)
796
value = ngx.HTTP_NOT_MODIFIED (304)
797
value = ngx.HTTP_BAD_REQUEST (400)
798
value = ngx.HTTP_UNAUTHORIZED (401)
799
value = ngx.HTTP_FORBIDDEN (403)
800
value = ngx.HTTP_NOT_FOUND (404)
801
value = ngx.HTTP_NOT_ALLOWED (405)
802
value = ngx.HTTP_GONE (410)
803
value = ngx.HTTP_INTERNAL_SERVER_ERROR (500)
804
value = ngx.HTTP_SERVICE_UNAVAILABLE (503)
669
807
Nginx log level constants
670
808
-------------------------
671
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
673
log_level = ngx.STDERR
674
log_level = ngx.EMERG
675
log_level = ngx.ALERT
679
log_level = ngx.NOTICE
681
log_level = ngx.DEBUG
685
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
687
Emit args concatenated to `error.log`, with log level `ngx.NOTICE` and prefix `lua print: `.
809
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
822
These constants are usually used by the [ngx.log](http://wiki.nginx.org/HttpLuaModule#ngx.log) method.
826
**syntax:** *print(...)*
828
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
830
Emit args concatenated to nginx's `error.log` file, with log level `ngx.NOTICE` and prefix `lua print: `.
689
832
It's equivalent to
691
834
ngx.log(ngx.NOTICE, 'lua print: ', a, b, ...)
693
Nil arguments are accepted and result in literal "nil".
695
ngx.location.capture(uri, options?)
696
-----------------------------------
697
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
699
Issue a synchronous but still non-blocking "nginx subrequest" using `uri`.
701
Nginx subrequests provide a powerful way to make
702
non-blocking internal requests to other locations
703
configured with disk file directory or *any*
704
other nginx C modules like
705
`ngx_proxy`, `ngx_fastcgi`, `ngx_memc`,
707
`ngx_drizzle`, and even `ngx_lua` itself and etc etc etc.
709
Also note that subrequests just mimic the HTTP
710
interface but there's *no*
711
extra HTTP/TCP traffic *nor* IPC involved. Everything
712
works internally, efficiently, on the C level.
714
Subrequests are completely different from HTTP 301/302 redirection (via `ngx.redirect()`) and internal redirection (via `ngx.exec()`).
836
Lua `nil` arguments are accepted and result in literal `"nil"`, and Lua booleans result in `"true"` or `"false"`.
840
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
842
This table can be used to store per-request context data for Lua programmers.
844
This table has a liftime identical to the current request (just like Nginx variables). Consider the following example,
848
ngx.say("foo = ", ngx.ctx.foo)
852
ngx.ctx.foo = ngx.ctx.foo + 3
859
Then `GET /test` will yield the output
864
That is, the `ngx.ctx.foo` entry persists across the rewrite, access, and content phases of a request.
866
Also, every request has its own copy, include subrequests, for example:
870
ngx.say("sub pre: ", ngx.ctx.blah)
872
ngx.say("sub post: ", ngx.ctx.blah)
879
ngx.say("main pre: ", ngx.ctx.blah)
880
local res = ngx.location.capture("/sub")
882
ngx.say("main post: ", ngx.ctx.blah)
886
Then `GET /main` will give the output
893
We can see that modification of the `ngx.ctx.blah` entry in the subrequest does not affect the one in its parent request. They do have two separate versions of `ngx.ctx.blah` per se.
895
Internal redirection will destroy the original request's `ngx.ctx` data (if any) and the new request will have an emptied `ngx.ctx` table. For instance,
905
ngx.ctx.foo = "hello"
910
Then `GET /orig` will give you
914
rather than the original `"hello"` value.
916
Arbitrary data values can be inserted into this "matic" table, including Lua closures and nested tables. You can also register your own meta methods with it.
918
Overriding `ngx.ctx` with a new Lua table is also supported, for example,
920
ngx.ctx = { foo = 32, bar = 54 }
925
**syntax:** *res = ngx.location.capture(uri, options?)*
927
**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua**
929
Issue a synchronous but still non-blocking *Nginx Subrequest* using `uri`.
931
Nginx subrequests provide a powerful way to make non-blocking internal requests to other locations configured with disk file directory or *any* other nginx C modules like `ngx_proxy`, `ngx_fastcgi`, `ngx_memc`,
932
`ngx_postgres`, `ngx_drizzle`, and even `ngx_lua` itself and etc etc etc.
934
Also note that subrequests just mimic the HTTP interface but there's *no* extra HTTP/TCP traffic *nor* IPC involved. Everything works internally, efficiently, on the C level.
936
Subrequests are completely different from HTTP 301/302 redirection (via [ngx.redirect](http://wiki.nginx.org/HttpLuaModule#ngx.redirect)) and internal redirection (via [ngx.exec](http://wiki.nginx.org/HttpLuaModule#ngx.exec)).
716
938
Here's a basic example:
832
1049
table.insert(reqs, { "/postgres" })
833
1050
table.insert(reqs, { "/redis" })
834
1051
table.insert(reqs, { "/memcached" })
836
1053
-- issue all the requests at once and wait until they all return
837
1054
local resps = { ngx.location.capture_multi(reqs) }
839
1056
-- loop over the responses table
840
1057
for i, resp in ipairs(resps) do
841
1058
-- process the response table "resp"
844
The `ngx.location.capture` function is just a special form
845
of this function. Logically speaking, the `ngx.location.capture` can be implemented like this
1061
The [ngx.location.capture](http://wiki.nginx.org/HttpLuaModule#ngx.location.capture) function is just a special form
1062
of this function. Logically speaking, the [ngx.location.capture](http://wiki.nginx.org/HttpLuaModule#ngx.location.capture) can be implemented like this
847
1064
ngx.location.capture =
848
1065
function (uri, args)
849
1066
return ngx.location.capture_multi({ {uri, args} })
854
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1072
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
856
Read and write the response status. This should be called
1074
Read and write the current request's response status. This should be called
857
1075
before sending out the response headers.
859
1077
ngx.status = ngx.HTTP_CREATED
860
1078
status = ngx.status
862
1081
ngx.header.HEADER
863
-----------------------
864
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
866
Set/add/clear response headers. Underscores (_) in the header names will be replaced by dashes (-) and the header names will be matched case-insentively.
1083
**syntax:** *ngx.header.HEADER = VALUE*
1085
**syntax:** *value = ngx.header.HEADER*
1087
**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1089
When assigning to `ngx.header.HEADER` will set, add, or clear the current request's response header named `HEADER`. Underscores (`_`) in the header names will be replaced by dashes (`-`) and the header names will be matched case-insensitively.
868
1092
-- equivalent to ngx.header["Content-Type"] = 'text/plain'
869
1093
ngx.header.content_type = 'text/plain';
871
1095
ngx.header["X-My-Header"] = 'blah blah';
873
1098
Multi-value headers can be set this way:
875
1101
ngx.header['Set-Cookie'] = {'a=32; path=/', 'b=4; path=/'}
879
1107
Set-Cookie: a=32; path=/
880
1108
Set-Cookie: b=4; path=/
882
1111
in the response headers. Only array-like tables are accepted.
884
Note that, for those standard headers that only accepts a single value, like Content-Type, only the last element
1113
Note that, for those standard headers that only accepts a single value, like `Content-Type`, only the last element
885
1114
in the (array) table will take effect. So
887
1117
ngx.header.content_type = {'a', 'b'}
889
1120
is equivalent to
891
1123
ngx.header.content_type = 'b'
893
Setting a slot to nil effectively removes it from the response headers:
1126
Setting a slot to `nil` effectively removes it from the response headers:
895
1129
ngx.header["X-My-Header"] = nil;
897
1132
same does assigning an empty table:
899
1135
ngx.header["X-My-Header"] = {};
901
`ngx.header` is not a normal Lua table so you cannot
904
For reading request headers, use `ngx.var.http_HEADER`, that is, nginx's standard $http_HEADER variables:
906
http://wiki.nginx.org/NginxHttpCoreModule#.24http_HEADER
908
Reading values from ngx.header.HEADER is not implemented yet, and usually you
1138
Setting `ngx.header.HEADER` after sending out response headers (either explicitly with [ngx.send_headers](http://wiki.nginx.org/HttpLuaModule#ngx.send_headers) or implicitly with [ngx.print](http://wiki.nginx.org/HttpLuaModule#ngx.print) and its friends) will throw out a Lua exception.
1140
Reading `ngx.header.HEADER` will return the value of the response header named `HEADER`. Underscores (`_`) in the header names will also be replaced by dashes (`-`) and the header names will be matched case-insensitively. If the response header is not present at all, `nil` will be returned.
1142
This is particularly useful in the context of [filter_header_by_lua](http://wiki.nginx.org/HttpLuaModule#filter_header_by_lua) and [filter_header_by_lua_file](http://wiki.nginx.org/HttpLuaModule#filter_header_by_lua_file), for example,
1148
proxy_pass http://some-backend;
1150
header_filter_by_lua '
1151
if ngx.header["X-My-Header"] == "blah" then
1152
ngx.var.footer = "some value"
1156
echo_after_body $footer;
1160
For multi-value headers, all of the values of header will be collected in order and returned as a Lua table. For example, response headers
1173
to be returned when reading `ngx.header.Foo`.
1175
Note that `ngx.header` is not a normal Lua table so you cannot iterate through it using Lua's `ipairs` function.
1177
For reading *request* headers, use the [ngx.req.get_headers](http://wiki.nginx.org/HttpLuaModule#ngx.req.get_headers) function instead.
1179
ngx.req.get_uri_args
1180
--------------------
1181
**syntax:** *args = ngx.req.get_uri_args()*
1183
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1185
Returns a Lua table holds all of the current request's request URL query arguments.
1191
local args = ngx.req.get_uri_args()
1192
for key, val in pairs(args) do
1193
if type(val) == "table" then
1194
ngx.say(key, ": ", table.concat(val, ", "))
1196
ngx.say(key, ": ", val)
1202
Then `GET /test?foo=bar&bar=baz&bar=blah` will yield the response body
1207
Multiple occurrences of an argument key will result in a table value holding all of the values for that key in order.
1209
Keys and values will be automatically unescaped according to URI escaping rules. For example, in the above settings, `GET /test?a%20b=1%61+2` will yield the output
1213
Arguments without the `=<value>` parts are treated as boolean arguments. For example, `GET /test?foo&bar` will yield the outputs
1218
That is, they will take Lua boolean values `true`. However, they're different from arguments taking empty string values. For example, `GET /test?foo=&bar=` will give something like
1223
Empty key arguments are discarded, for instance, `GET /test?=hello&=world` will yield empty outputs.
1225
Updating query arguments via the nginx variable `$args` (or `ngx.var.args` in Lua) at runtime are also supported:
1227
ngx.var.args = "a=3&b=42"
1228
local args = ngx.req.get_uri_args()
1230
Here the `args` table will always look like
1234
regardless of the actual request query string.
1236
ngx.req.get_post_args
1237
---------------------
1238
**syntax:** *ngx.req.get_post_args()*
1240
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1242
Returns a Lua table holds all of the current request's POST query arguments. It's required to turn on the [lua_need_request_body](http://wiki.nginx.org/HttpLuaModule#lua_need_request_body) directive, or a Lua exception will be thrown.
1247
lua_need_request_body on;
1249
local args = ngx.req.get_post_args()
1250
for key, val in pairs(args) do
1251
if type(val) == "table" then
1252
ngx.say(key, ": ", table.concat(val, ", "))
1254
ngx.say(key, ": ", val)
1262
# Post request with the body 'foo=bar&bar=baz&bar=blah'
1263
$ curl --data 'foo=bar&bar=baz&bar=blah' localhost/test
1265
will yield the response body like
1270
Multiple occurrences of an argument key will result in a table value holding all of the values for that key in order.
1272
Keys and values will be automatically unescaped according to URI escaping rules. For example, in the above settings,
1274
# POST request with body 'a%20b=1%61+2'
1275
$ curl -d 'a%20b=1%61+2' localhost/test
1277
will yield the output
1281
Arguments without the `=<value>` parts are treated as boolean arguments. For example, `GET /test?foo&bar` will yield the outputs
1286
That is, they will take Lua boolean values `true`. However, they're different from arguments taking empty string values. For example, `POST /test` with request body `foo=&bar=` will give something like
1291
Empty key arguments are discarded, for instance, `POST /test` with body `=hello&=world` will yield empty outputs.
912
1294
-------------------
913
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
915
Does an internal redirect to uri with args.
1295
**syntax:** *headers = ngx.req.get_headers()*
1297
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1299
Returns a Lua table holds all of the current request's request headers.
1303
local h = ngx.req.get_headers()
1304
for k, v in pairs(h) do
1308
To read an individual header:
1310
ngx.say("Host: ", ngx.req.get_headers()["Host"])
1312
For multiple instances of request headers like
1318
the value of `ngx.req.get_headers()["Foo"]` will be a Lua (array) table like this:
1320
{"foo", "bar", "baz"}
1322
Another way to read individual request headers is to use `ngx.var.http_HEADER`, that is, nginx's standard [$http_HEADER](http://wiki.nginx.org/HttpCoreModule#.24http_HEADER) variables.
1326
**syntax:** *ngx.req.set_header(header_name, header_value)*
1328
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1330
Set the current request's request header named `header_name` to value `header_value`, overriding any existing ones.
1331
None of the current request's subrequests will be affected.
1333
Here's an example of setting the `Content-Length` header:
1335
ngx.req.set_header("Content-Type", "text/css")
1337
The `header_value` can take an array list of values,
1340
ngx.req.set_header("Foo", {"a", "abc"})
1342
will produce two new request headers:
1347
and old `Foo` headers will be overridden if there's any.
1349
When the `header_value` argument is `nil`, the request header will be removed. So
1351
ngx.req.set_header("X-Foo", nil)
1355
ngx.req.clear_header("X-Foo")
1358
ngx.req.clear_header
1359
--------------------
1360
**syntax:** *ngx.req.clear_header(header_name)*
1362
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1364
Clear the current request's request header named `header_name`. None of the current request's subrequests will be affected.
1368
**syntax:** *ngx.exec(uri, args?)*
1370
**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua**
1372
Does an internal redirect to `uri` with `args`.
917
1375
ngx.exec('/some-location');
918
1376
ngx.exec('/some-location', 'a=3&b=5&c=6');
919
1377
ngx.exec('/some-location?a=3&b=5', 'c=6');
921
Named locations are also supported, but query strings are ignored. For example
1380
Named locations are also supported, but query strings are ignored. For example,
924
1384
content_by_lua '
925
1385
ngx.exec("@bar");
933
Note that this is very different from ngx.redirect() in that
1394
The optional second `args` can be used to specify extra URI query arguments, for example:
1397
ngx.exec("/foo", "a=3&b=hello%20world")
1400
Alternatively, you can pass a Lua table for the `args` argument and let ngx_lua do URI escaping and string concatenation automatically for you, for instance,
1403
ngx.exec("/foo", { a = 3, b = "hello world" })
1406
The result is exactly the same as the previous example.
1408
Note that this is very different from [ngx.redirect](http://wiki.nginx.org/HttpLuaModule#ngx.redirect) in that
934
1409
it's just an internal redirect and no new HTTP traffic is involved.
936
1411
This method never returns.
938
This method MUST be called before `ngx.send_headers()` or explicit response body
939
outputs by either `ngx.print` or `ngx.say`.
941
This method is very much like the `echo_exec`
942
directive in the ngx_echo module.
944
ngx.redirect(uri, status?)
945
--------------------------
946
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
948
Issue an HTTP 301 or 302 redirection to `uri`.
1413
This method *must* be called before [ngx.send_headers](http://wiki.nginx.org/HttpLuaModule#ngx.send_headers) or explicit response body
1414
outputs by either [ngx.print](http://wiki.nginx.org/HttpLuaModule#ngx.print) or [ngx.say](http://wiki.nginx.org/HttpLuaModule#ngx.say).
1416
This method is very much like the [echo_exec](http://wiki.nginx.org/HttpEchoModule#echo_exec) directive in [HttpEchoModule](http://wiki.nginx.org/HttpEchoModule).
1420
**syntax:** *ngx.redirect(uri, status?)*
1422
**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua**
1424
Issue an `HTTP 301` or <code>302` redirection to <code>uri`.
950
1426
The optional `status` parameter specifies whether
951
301 or 302 to be used. It's 302 (ngx.HTTP_MOVED_TEMPORARILY) by default.
1427
`301` or `302` to be used. It's `302` (`ngx.HTTP_MOVED_TEMPORARILY`) by default.
953
1429
Here's a small example:
955
1432
return ngx.redirect("/foo")
957
1435
which is equivalent to
959
1438
return ngx.redirect("http://localhost:1984/foo", ngx.HTTP_MOVED_TEMPORARILY)
961
1441
assuming the current server name is `localhost` and it's listening on the `1984` port.
963
This method MUST be called before `ngx.send_headers()` or explicit response body
964
outputs by either `ngx.print` or `ngx.say`.
1443
This method *must* be called before [ngx.send_headers](http://wiki.nginx.org/HttpLuaModule#ngx.send_headers) or explicit response body outputs by either [ngx.print](http://wiki.nginx.org/HttpLuaModule#ngx.print) or [ngx.say](http://wiki.nginx.org/HttpLuaModule#ngx.say).
966
1445
This method never returns.
968
This method is very much like the `rewrite` directive with the `redirect` modifier in the standard
969
`ngx_rewrite` module, for example, this nginx.conf snippet
1447
This method is very much like the [rewrite](http://wiki.nginx.org/HttpRewriteModule#rewrite) directive with the `redirect` modifier in the standard
1448
[HttpRewriteModule](http://wiki.nginx.org/HttpRewriteModule), for example, this `nginx.conf` snippet
971
1451
rewrite ^ /foo redirect; # nginx config
973
1454
is equivalent to the following Lua code
975
1457
return ngx.redirect('/foo'); -- lua code
979
1463
rewrite ^ /foo permanent; # nginx config
981
1466
is equivalent to
983
1469
return ngx.redirect('/foo', ngx.HTTP_MOVED_PERMANENTLY) -- Lua code
987
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1474
**syntax:** *ngx.send_headers()*
1476
**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua**
989
1478
Explicitly send out the response headers.
991
Usually you don't have to send headers yourself. ngx_lua
992
will automatically send out headers right before you
993
output contents via `ngx.say` or `ngx.print`.
995
Headers will also be sent automatically when `content_by_lua` exits normally.
999
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1001
Emit args concatenated to the HTTP client (as response body).
1003
Nil arguments are not allowed.
1007
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1009
Just as `ngx.print` but also emit a trailing newline.
1011
Nil arguments are not allowed.
1013
ngx.log(log_level, ...)
1014
-----------------------
1015
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1017
Log args concatenated to error.log with the given logging level.
1019
Nil arguments are accepted and result in literal "nil".
1023
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1025
Force flushing the response outputs.
1480
Usually you don't have to send headers yourself. `ngx_lua` will automatically send out headers right before you
1481
output contents via [ngx.say](http://wiki.nginx.org/HttpLuaModule#ngx.say) or [ngx.print](http://wiki.nginx.org/HttpLuaModule#ngx.print).
1483
Headers will also be sent automatically when [content_by_lua](http://wiki.nginx.org/HttpLuaModule#content_by_lua) exits normally.
1028
1486
----------------
1029
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1031
Interrupts the execution of the current Lua thread and returns
1032
status code to nginx.
1487
**syntax:** *value = ngx.headers_sent*
1489
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1491
Returns `true` if the response headers have been sent (by ngx_lua), and `false` otherwise.
1493
This API was first introduced in ngx_lua v0.3.1rc6.
1497
**syntax:** *ngx.print(...)*
1499
**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua**
1501
Emit arguments concatenated to the HTTP client (as response body). If response headers have not been sent yet, this function will first send the headers out, and then output the body data.
1503
Lua `nil` value will result in outputing `"nil"`, and Lua boolean values will emit literal `"true"` or `"false"`, accordingly.
1505
Also, nested arrays of strings are also allowed. The elements in the arrays will be sent one by one. For example
1510
{"world: ", true, " or ", false,
1516
will yield the output
1519
hello, world: true or false: nil
1522
Non-array table arguments will cause a Lua exception to be thrown.
1526
**syntax:** *ngx.say(...)*
1528
**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua**
1530
Just as [ngx.print](http://wiki.nginx.org/HttpLuaModule#ngx.print) but also emit a trailing newline.
1534
**syntax:** *ngx.log(log_level, ...)*
1536
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1538
Log arguments concatenated to error.log with the given logging level.
1540
Lua `nil` arguments are accepted and result in literal `"nil"`, and Lua booleans result in literal `"true"` or `"false"` outputs.
1542
The `log_level` argument can take constants like `ngx.ERR` and `ngx.WARN`. Check out [Nginx log level constants](http://wiki.nginx.org/HttpLuaModule#Nginx_log_level_constants) for details.
1546
**syntax:** *ngx.flush()*
1548
**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua**
1550
Force flushing the response outputs. This operation has no effect in HTTP 1.0 buffering output mode. See [HTTP 1.0 support](http://wiki.nginx.org/HttpLuaModule#HTTP_1.0_support).
1554
**syntax:** *ngx.exit(status)*
1556
**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua**
1558
When `status >= 200` (i.e., `ngx.HTTP_OK` and above), it will interrupt the execution of the current request and return status code to nginx.
1560
When `status == 0` (i.e., `ngx.OK`), it will only quit the current phase handler (or the content handler if the [content_by_lua](http://wiki.nginx.org/HttpLuaModule#content_by_lua) directive is used) and continue to run laster phases (if any) for the current request.
1034
1562
The `status` argument can be `ngx.OK`, `ngx.ERROR`, `ngx.HTTP_NOT_FOUND`,
1035
`ngx.HTTP_MOVED_TEMPORARILY`,
1036
or other HTTP status numbers.
1040
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1563
`ngx.HTTP_MOVED_TEMPORARILY`, or other [HTTP status constants](http://wiki.nginx.org/HttpLuaModule#HTTP_status_constants).
1565
To return an error page with custom contents, use code snippets like this:
1568
ngx.status = ngx.HTTP_GONE
1569
ngx.say("This is our own content")
1570
-- to cause quit the whole request rather than the current phase handler
1571
ngx.exit(ngx.HTTP_OK)
1574
The effect in action:
1577
$ curl -i http://localhost/test
1580
Date: Thu, 15 Sep 2011 00:51:48 GMT
1581
Content-Type: text/plain
1582
Transfer-Encoding: chunked
1583
Connection: keep-alive
1585
This is our own content
1590
**syntax:** *ngx.eof()*
1592
**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua**
1042
1594
Explicitly specify the end of the response output stream.
1046
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1598
**syntax:** *newstr = ngx.escape_uri(str)*
1600
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1048
1602
Escape `str` as a URI component.
1050
newstr = ngx.escape_uri(str)
1052
ngx.unescape_uri(str)
1053
---------------------
1054
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1056
Unescape `str` as a escaped URI component.
1058
newstr = ngx.unescape_uri(str)
1060
ngx.encode_base64(str)
1061
----------------------
1062
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1064
Encode `str` to a base64 digest
1066
newstr = ngx.encode_base64(str)
1068
ngx.decode_base64(str)
1069
----------------------
1070
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1072
Decode `str` as a base64 digest to the raw form
1074
newstr = ngx.decode_base64(str)
1606
**syntax:** *newstr = ngx.unescape_uri(str)*
1608
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1610
Unescape `str` as an escaped URI component.
1614
**syntax:** *newstr = ngx.encode_base64(str)*
1616
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1618
Encode `str` to a base64 digest.
1622
**syntax:** *newstr = ngx.decode_base64(str)*
1624
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1626
Decodes the `str` argument as a base64 digest to the raw form. Returns `nil` if `str` is not well formed.
1077
1629
---------------
1078
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1630
**syntax:** *intval = ngx.crc32_short(str)*
1632
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1634
Calculates the CRC-32 (Cyclic Redundancy Code) digest for the `str` argument.
1636
This method performs better on relatively short `str` inputs (i.e., less than 30 ~ 60 bytes), as compared to [ngx.crc32_long](http://wiki.nginx.org/HttpLuaModule#ngx.crc32_long). The result is exactly the same as [ngx.crc32_long](http://wiki.nginx.org/HttpLuaModule#ngx.crc32_long).
1638
Behind the scene, it is just a thin wrapper around the `ngx_crc32_short` function defined in the Nginx core.
1640
This API was first introduced in the `v0.3.1rc8` release.
1644
**syntax:** *intval = ngx.crc32_long(str)*
1646
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1648
Calculates the CRC-32 (Cyclic Redundancy Code) digest for the `str` argument.
1650
This method performs better on relatively long `str` inputs (i.e., longer than 30 ~ 60 bytes), as compared to [ngx.crc32_short](http://wiki.nginx.org/HttpLuaModule#ngx.crc32_short). The result is exactly the same as [ngx.crc32_short](http://wiki.nginx.org/HttpLuaModule#ngx.crc32_short).
1652
Behind the scene, it is just a thin wrapper around the `ngx_crc32_long` function defined in the Nginx core.
1654
This API was first introduced in the `v0.3.1rc8` release.
1658
**syntax:** *str = ngx.today()*
1660
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1080
1662
Returns today's date (in the format `yyyy-mm-dd`) from nginx cached time (no syscall involved unlike Lua's date library).
1083
1664
This is the local time.
1087
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1668
**syntax:** *secs = ngx.time()*
1670
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1089
1672
Returns the elapsed seconds from the epoch for the current timestamp from the nginx cached time (no syscall involved unlike Lua's date library).
1093
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1095
Returns the current timestamp (in the format `yyyy-mm-dd hh:mm:ss`) of the nginx cached time (no syscall involved unlike Lua's date library).
1676
**syntax:** *str = ngx.localtime()*
1678
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1680
Returns the current timestamp (in the format `yyyy-mm-dd hh:mm:ss`) of the nginx cached time (no syscall involved unlike Lua's [os.date](http://www.lua.org/manual/5.1/manual.html#pdf-os.date) function).
1097
1682
This is the local time.
1101
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1103
Returns the current timestamp (in the format `yyyy-mm-dd hh:mm:ss`) of the nginx cached time (no syscall involved unlike Lua's date library).
1686
**syntax:** *str = ngx.utctime()*
1688
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1690
Returns the current timestamp (in the format `yyyy-mm-dd hh:mm:ss`) of the nginx cached time (no syscall involved unlike Lua's [os.date](http://www.lua.org/manual/5.1/manual.html#pdf-os.date) function).
1105
1692
This is the UTC time.
1107
ngx.cookie_time(sec)
1108
--------------------
1109
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1111
Returns a formated string can be used as the cookie expiration time. The parameter `sec` is the timestamp in seconds (like those returned from `ngx.time`).
1696
**syntax:** *str = ngx.cookie_time(sec)*
1698
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1700
Returns a formated string can be used as the cookie expiration time. The parameter `sec` is the timestamp in seconds (like those returned from [ngx.time](http://wiki.nginx.org/HttpLuaModule#ngx.time)).
1113
1702
ngx.say(ngx.cookie_time(1290079655))
1114
1703
-- yields "Thu, 18-Nov-10 11:27:35 GMT"
1707
**syntax:** *str = ngx.http_time(sec)*
1709
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1711
Returns a formated string can be used as the http header time (for example, being used in `Last-Modified` header). The parameter `sec` is the timestamp in seconds (like those returned from [ngx.time](http://wiki.nginx.org/HttpLuaModule#ngx.time)).
1713
ngx.say(ngx.http_time(1290079655))
1714
-- yields "Thu, 18 Nov 10 11:27:35 GMT"
1718
**syntax:** *sec = ngx.parse_http_time(str)*
1720
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1722
Parse the http time string (as returned by [ngx.http_time](http://wiki.nginx.org/HttpLuaModule#ngx.http_time)) into seconds. Returns the seconds or `nil` if the input string is in bad forms.
1724
local time = ngx.parse_http_time("Thu, 18 Nov 10 11:27:35 GMT")
1116
1729
ngx.is_subrequest
1117
1730
-----------------
1118
* **Context:** `set_by_lua*`, `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1120
Returns true if the current request is an nginx subrequest, or false otherwise.
1731
**syntax:** *value = ngx.is_subrequest*
1733
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1735
Returns `true` if the current request is an nginx subrequest, or `false` otherwise.
1739
**syntax:** *captures = ngx.re.match(subject, regex, options?, ctx?)*
1741
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1743
Matches the `subject` string using the Perl-compatible regular expression `regex` with the optional `options`.
1745
Only the first occurrence of the match is returned, or `nil` if no match is found. In case of fatal errors, like seeing bad `UTF-8` sequences in `UTF-8` mode, a Lua exception will be raised.
1747
When a match is found, a Lua table `captures` is returned, where `captures[0]` holds the whole substring being matched, and `captures[1]` holds the first parenthesized subpattern's capturing, `captures[2]` the second, and so on. Here's some examples:
1750
local m = ngx.re.match("hello, 1234", "[0-9]+")
1755
local m = ngx.re.match("hello, 1234", "([0-9])[0-9]+")
1760
Unmatched subpatterns will take `nil` values in their `captures` table fields. For instance,
1763
local m = ngx.re.match("hello, world", "(world)|(hello)")
1769
Escaping sequences in Perl-compatible regular expressions like `\d`, `\s`, and `\w`, require special care when specifying them in Lua string literals, because the backslash character, `\`, needs to be escaped in Lua string literals too, for example,
1772
? m = ngx.re.match("hello, 1234", "\d+")
1775
won't work as expected and won't match at all. Intead, you should escape the backslash itself and write
1778
m = ngx.re.match("hello, 1234", "\\d+")
1781
When you put the Lua code snippet in your `nginx.conf` file, you have to escape the backslash one more time, because your Lua code is now in an nginx string literal, and backslashes in nginx string literals require escaping as well. For instance,
1786
local m = ngx.re.match("hello, 1234", "\\\\d+")
1787
if m then ngx.say(m[0]) else ngx.say("not matched!") end
1792
You can also specify `options` to control how the match will be performed. The following option characters are supported:
1795
a anchored mode (only match from the beginning)
1796
i caseless mode (just like Perl's /i modifier)
1797
m multi-line mode (just like Perl's /m modifier)
1798
o compile-once mode (similar to Perl's /o modifer),
1799
to enable the worker-process-level compiled-regex cache
1800
s single-line mode (just like Perl's /s modifier)
1802
x extended mode (just like Perl's /x modifier)
1805
These characters can be combined together, for example,
1808
local m = ngx.re.match("hello, world", "HEL LO", "ix")
1813
local m = ngx.re.match("hello, 美好生活", "HELLO, (.{2})", "iu")
1814
-- m[0] == "hello, 美好"
1818
The `o` regex option is good for performance tuning, because the regex in question will only be compiled once, cached in the worker-process level, and shared among all the requests in the current Nginx worker process. You can tune the upper limit of the regex cache via the [lua_regex_cache_max_entries](http://wiki.nginx.org/HttpLuaModule#lua_regex_cache_max_entries) directive.
1820
The optional fourth argument, `ctx`, can be a Lua table holding an optional `pos` field. When the `pos` field in the `ctx` table argument is specified, `ngx.re.match` will start matching from that offset. Regardless of the presence of the `pos` field in the `ctx` table, `ngx.re.match` will always set this `pos` field to the position *after* the substring matched by the whole pattern in case of a successful match. When match fails, the `ctx` table will leave intact. Here is some examples,
1824
local m = ngx.re.match("1234, hello", "[0-9]+", "", ctx)
1830
local ctx = { pos = 2 }
1831
local m = ngx.re.match("1234, hello", "[0-9]+", "", ctx)
1836
The `ctx` table argument combined with the `a` regex modifier can be used to construct a lexer atop `ngx.re.match`.
1838
Note that, the `options` argument is not optional when the `ctx` argument is specified; use the empty Lua string (`""`) as the placeholder for `options` if you do not want to specify any regex options.
1840
This method requires the PCRE library enabled in your Nginx build.
1842
This feature is introduced in the `v0.2.1rc11` release.
1846
**syntax:** *iterator = ngx.re.gmatch(subject, regex, options?)*
1848
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1850
Similar to [ngx.re.match](http://wiki.nginx.org/HttpLuaModule#ngx.re.match), but returns a Lua iterator instead, so as to let the user programmer iterate all the matches over the `<subject>` string argument with the Perl-compatible regular expression `regex`.
1852
Here's a small exmple to demonstrate its basic usage:
1855
local iterator = ngx.re.gmatch("hello, world!", "([a-z]+)", "i")
1857
m = iterator() -- m[0] == m[1] == "hello"
1858
m = iterator() -- m[0] == m[1] == "world"
1859
m = iterator() -- m == nil
1862
More often we just put it into a Lua `for` loop:
1865
for m in ngx.re.gmatch("hello, world!", "([a-z]+)", "i")
1871
The optional `options` argument takes exactly the same semantics as the [ngx.re.match](http://wiki.nginx.org/HttpLuaModule#ngx.re.match) method.
1873
The current implementation requires that the iterator returned should only be used in a single request. That is, one should *not* assign it to a variable belonging to persistent namespace like a Lua package.
1875
This method requires the PCRE library enabled in your Nginx build.
1877
This feature was first introduced in the `v0.2.1rc12` release.
1881
**syntax:** *newstr, n = ngx.re.sub(subject, regex, replace, options?)*
1883
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1885
Substitutes the first match of the Perl-compatible regular expression `regex` on the `subject` argument string with the string or function argument `replace`. The optional `options` argument has exactly the same meaning as in [ngx.re.match](http://wiki.nginx.org/HttpLuaModule#ngx.re.match).
1887
This method returns the resulting new string as well as the number of successful substitutions, or throw out a Lua exception when an error occurred (syntax errors in the `<replace>` string argument, for example).
1889
When the `replace` is a string, then it is treated as a special template for string replacement. For example,
1892
local newstr, n = ngx.re.sub("hello, 1234", "([0-9])[0-9]", "[$0][$1]")
1893
-- newstr == "hello, [12][1]34"
1897
where `$0` referring to the whole substring matched by the pattern and `$1` referring to the first parenthesized capturing substring.
1899
You can also use curly braces to disambiguate variable names from the background string literals:
1902
local newstr, n = ngx.re.sub("hello, 1234", "[0-9]", "${0}00")
1903
-- newstr == "hello, 10034"
1907
Literal dollar sign characters (`$`) in the `replace` string argument can be escaped by another dollar sign, for instance,
1910
local newstr, n = ngx.re.sub("hello, 1234", "[0-9]", "$$")
1911
-- newstr == "hello, $234"
1915
Do not use backlashes to escape dollar signs; it won't work as expected.
1917
When the `replace` argument is of type "function", then it will be invoked with the "match table" as the argument to generate the replace string literal for substitution. The "match table" fed into the `replace` function is exactly the same as the return value of [ngx.re.match](http://wiki.nginx.org/HttpLuaModule#ngx.re.match). Here is an example:
1920
local func = function (m)
1921
return "[" .. m[0] .. "][" .. m[1] .. "]"
1923
local newstr, n = ngx.re.sub("hello, 1234", "( [0-9] ) [0-9]", func, "x")
1924
-- newstr == "hello, [12][1]34"
1928
The dollar sign characters in the return value of the `replace` function argument are not special at all.
1930
This method requires the PCRE library enabled in your Nginx build.
1932
This feature was first introduced in the `v0.2.1rc13` release.
1936
**syntax:** *newstr, n = ngx.re.gsub(subject, regex, replace, options?)*
1938
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1940
Just like [ngx.re.sub](http://wiki.nginx.org/HttpLuaModule#ngx.re.sub), but does global substitution.
1942
Here is some examples:
1945
local newstr, n = ngx.re.gsub("hello, world", "([a-z])[a-z]+", "[$0,$1]", "i")
1946
-- newstr == "[hello,h], [world,w]"
1951
local func = function (m)
1952
return "[" .. m[0] .. "," .. m[1] .. "]"
1954
local newstr, n = ngx.re.gsub("hello, world", "([a-z])[a-z]+", func, "i")
1955
-- newstr == "[hello,h], [world,w]"
1959
This method requires the PCRE library enabled in your Nginx build.
1961
This feature was first introduced in the `v0.2.1rc15` release.
1122
1963
ndk.set_var.DIRECTIVE
1123
1964
---------------------
1124
* **Context:** `rewrite_by_lua*`, `access_by_lua*`, `content_by_lua*`
1126
This mechanism allows calling other nginx C modules' directives that are
1127
implemented by Nginx Devel Kit (NDK)'s set_var submodule's ndk_set_var_value.
1129
For example, ngx_set_misc module's set_escape_uri, set_quote_sql_str, and etc.
1965
**syntax:** *res = ndk.set_var.DIRECTIVE_NAME*
1967
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua**
1969
This mechanism allows calling other nginx C modules' directives that are implemented by [Nginx Devel Kit](https://github.com/simpl/ngx_devel_kit) (NDK)'s set_var submodule's `ndk_set_var_value`.
1971
For example, [HttpSetMiscModule](http://wiki.nginx.org/HttpSetMiscModule)'s following directives can be invoked this way:
1973
* [set_quote_sql_str](http://wiki.nginx.org/HttpSetMiscModule#set_quote_sql_str)
1974
* [set_quote_pgsql_str](http://wiki.nginx.org/HttpSetMiscModule#set_quote_pgsql_str)
1975
* [set_quote_json_str](http://wiki.nginx.org/HttpSetMiscModule#set_quote_json_str)
1976
* [set_unescape_uri](http://wiki.nginx.org/HttpSetMiscModule#set_unescape_uri)
1977
* [set_escape_uri](http://wiki.nginx.org/HttpSetMiscModule#set_escape_uri)
1978
* [set_encode_base32](http://wiki.nginx.org/HttpSetMiscModule#set_encode_base32)
1979
* [set_decode_base32](http://wiki.nginx.org/HttpSetMiscModule#set_decode_base32)
1980
* [set_encode_base64](http://wiki.nginx.org/HttpSetMiscModule#set_encode_base64)
1981
* [set_decode_base64](http://wiki.nginx.org/HttpSetMiscModule#set_decode_base64)
1982
* [set_encode_hex](http://wiki.nginx.org/HttpSetMiscModule#set_encode_base64)
1983
* [set_decode_hex](http://wiki.nginx.org/HttpSetMiscModule#set_decode_base64)
1984
* [set_sha1](http://wiki.nginx.org/HttpSetMiscModule#set_encode_base64)
1985
* [set_md5](http://wiki.nginx.org/HttpSetMiscModule#set_decode_base64)
1133
1990
local res = ndk.set_var.set_escape_uri('a/b');
1134
1991
-- now res == 'a%2fb'
1994
Similarly, the following directives provided by [HttpEncryptedSessionModule](http://wiki.nginx.org/HttpEncryptedSessionModule) can be invoked from within Lua too:
1996
* [set_encrypt_session](http://wiki.nginx.org/HttpEncryptedSessionModule#set_encrypt_session)
1997
* [set_decrypt_session](http://wiki.nginx.org/HttpEncryptedSessionModule#set_decrypt_session)
1999
This feature requires the [ngx_devel_kit](https://github.com/simpl/ngx_devel_kit) module.
1136
2001
HTTP 1.0 support
1139
2004
The HTTP 1.0 protocol does not support chunked outputs and always requires an
1140
2005
explicit `Content-Length` header when the response body is non-empty. So when
1141
2006
an HTTP 1.0 request is present, This module will automatically buffer all the
1142
outputs of user calls of `ngx.say()` and `ngx.print()` and
2007
outputs of user calls of [ngx.say](http://wiki.nginx.org/HttpLuaModule#ngx.say) and [ngx.print](http://wiki.nginx.org/HttpLuaModule#ngx.print) and
1143
2008
postpone sending response headers until it sees all the outputs in the response
1144
2009
body, and at that time ngx_lua can calculate the total length of the body and
1145
2010
construct a proper `Content-Length` header for the HTTP 1.0 client.
1357
2228
assuming your current Lua module is named `foo.bar`. This will guarantee that you have declared your Lua functions' local Lua variables as "local" in your Lua modules, or bad race conditions while accessing these variables under load will tragically happen. See the `Data Sharing within an Nginx Worker` for the reasons of this danger.
1360
Data Sharing within an Nginx Worker
1361
===================================
1363
**NOTE: This mechanism behaves differently when code cache is turned off, and should be considered as a DIRTY TRICK. Backward compatibility is NOT guaranteed. Use at your own risk! We're going to design a whole new data-sharing mechanism.**
1365
If you want to globally share user data among all the requests handled by the same nginx worker process, you can encapsulate your shared data into a Lua module, require the module in your code, and manipulate shared data through it. It works because required Lua modules are loaded only once, and all coroutines will share the same copy of the module.
1367
Here's a complete small example:
1370
module("mydata", package.seeall)
1378
function get_age(name)
1382
and then accessing it from your nginx.conf:
1385
content_lua_by_lua '
1386
local mydata = require("mydata")
1387
ngx.say(mydata.get_age("dog"))
1391
Your `mydata` module in this example will only be loaded
1392
and run on the first request to the location `/lua`,
1393
and all those subsequent requests to the same nginx
1394
worker process will use the reloaded instance of the
1395
module as well as the same copy of the data in it,
1396
until you send a `HUP` signal to the nginx master
1397
process to enforce a reload.
1399
This data sharing technique is essential for high-performance Lua apps built atop this module. It's common to cache reusable data globally.
1401
It's worth noting that this is *per-worker* sharing, not *per-server* sharing. That is, when you have multiple nginx worker processes under an nginx master, this data sharing cannot pass process boundry. If you indeed need server-wide data sharing, you can
1403
1. Use only a single nginx worker and a single server. This is not recommended when you have a mulit-core CPU or multiple CPUs in a single machine.
1404
2. Use some true backend storage like `memcached`, `redis`, or an RDBMS like `mysql`.
1409
* "Introduction to ngx_lua" ( <https://github.com/chaoslawful/lua-nginx-module/wiki/Introduction> )
1410
* ngx_devel_kit ( <http://github.com/simpl/ngx_devel_kit> )
1411
* echo-nginx-module ( <http://github.com/agentzh/echo-nginx-module> )
1412
* drizzle-nginx-module ( <http://github.com/chaoslawful/drizzle-nginx-module> )
1413
* postgres-nginx-module ( <http://github.com/FRiCKLE/ngx_postgres> )
1414
* memc-nginx-module ( <http://github.com/agentzh/memc-nginx-module> )
2237
* added the [header_filter_by_lua](http://wiki.nginx.org/HttpLuaModule#header_filter_by_lua) and [header_filter_by_lua_file](http://wiki.nginx.org/HttpLuaModule#header_filter_by_lua_file) directives. thanks Liseen Wan (万珣新).
2238
* implemented the PCRE regex API for Lua: [ngx.re.match](http://wiki.nginx.org/HttpLuaModule#ngx.re.match), [ngx.re.gmatch](http://wiki.nginx.org/HttpLuaModule#ngx.re.gmatch), [ngx.re.sub](http://wiki.nginx.org/HttpLuaModule#ngx.re.sub), and [ngx.re.gsub](http://wiki.nginx.org/HttpLuaModule#ngx.re.gsub).
2239
* now we add the `ngx` and `ndk` table into `package.loaded` such that the user can write `local ngx = require 'ngx'` and `local ndk = require 'ndk'`. thanks @Lance.
2240
* added new directive [lua_regex_cache_max_entries](http://wiki.nginx.org/HttpLuaModule#lua_regex_cache_max_entries) to control the upper limit of the worker-process-level compiled-regex cache enabled by the `o` regex option.
2241
* implemented the special [ngx.ctx](http://wiki.nginx.org/HttpLuaModule#ngx.ctx) Lua table for user programmers to store per-request Lua context data for their applications. thanks 欧远宁 for suggesting this feature.
2242
* now [ngx.print](http://wiki.nginx.org/HttpLuaModule#ngx.print) and [ngx.say](http://wiki.nginx.org/HttpLuaModule#ngx.say) allow (nested) array-like table arguments. the array elements in them will be sent piece by piece. this will avoid string concatenation for templating engines like [ltp](http://www.savarese.com/software/ltp/).
2243
* implemented the [ngx.req.get_post_args](http://wiki.nginx.org/HttpLuaModule#ngx.req.get_post_args) method for fetching url-encoded POST query arguments from within Lua.
2244
* implemented the [ngx.req.get_uri_args](http://wiki.nginx.org/HttpLuaModule#ngx.req.get_uri_args) method to fetch parsed URL query arguments from within Lua. thanks Bertrand Mansion (golgote).
2245
* added new function [ngx.parse_http_time](http://wiki.nginx.org/HttpLuaModule#ngx.parse_http_time), thanks James Hurst.
2246
* now we allow Lua boolean and `nil` values in arguments to [ngx.say](http://wiki.nginx.org/HttpLuaModule#ngx.say), [ngx.print](http://wiki.nginx.org/HttpLuaModule#ngx.print), [ngx.log](http://wiki.nginx.org/HttpLuaModule#ngx.log) and [print](http://wiki.nginx.org/HttpLuaModule#print).
2247
* added support for user C macros `LUA_DEFAULT_PATH` and `LUA_DEFAULT_CPATH`. for now we can only define them in `ngx_lua`'s `config` file because nginx `configure`'s `--with-cc-opt` option hates values with double-quotes in them. sigh. [ngx_openresty](http://openresty.org/) is already using this feature to bundle 3rd-party Lua libraries.
2251
* worked-around the "stack overflow" issue while using `luarocks.loader` and disabling [lua_code_cache](http://wiki.nginx.org/HttpLuaModule#lua_code_cache), as described as github issue #27. thanks Patrick Crosby.
2252
* fixed the `zero size buf in output` alert while combining [lua_need_request_body](http://wiki.nginx.org/HttpLuaModule#lua_need_request_body) on + [access_by_lua](http://wiki.nginx.org/HttpLuaModule#access_by_lua)/[rewrite_by_lua](http://wiki.nginx.org/HttpLuaModule#rewrite_by_lua) + [proxy_pass](http://wiki.nginx.org/HttpProxyModule#proxy_pass)/[fastcgi_pass](http://wiki.nginx.org/HttpFcgiModule#fastcgi_pass). thanks Liseen Wan (万珣新).
2253
* fixed issues with HTTP 1.0 HEAD requests.
2254
* made setting `ngx.header.HEADER` after sending out response headers throw out a Lua exception to help debugging issues like github issue #49. thanks Bill Donahue (ikhoyo).
2255
* fixed an issue regarding defining global variables in C header files: we should have defined the global `ngx_http_lua_exception` in a single compilation unit. thanks @姜大炮.
1419
2260
* chaoslawful (王晓哲) <chaoslawful at gmail dot com>
1420
* Yichun "agentzh" Zhang (章亦春) <agentzh at gmail dot com>
2261
* Zhang "agentzh" Yichun (章亦春) <agentzh at gmail dot com>
1422
2263
Copyright & License
1423
2264
===================
1425
This module is licenced under the BSD license.
1427
Copyright (C) 2009, 2010, 2011, Taobao Inc., Alibaba Group ( http://www.taobao.com ).
1429
Copyright (C) 2009, 2010, 2011, by Xiaozhe Wang (chaoslawful) <chaoslawful@gmail.com>.
1431
Copyright (C) 2009, 2010, 2011, by Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>.
1433
All rights reserved.
1435
Redistribution and use in source and binary forms, with or without
1436
modification, are permitted provided that the following conditions
1439
* Redistributions of source code must retain the above copyright
1440
notice, this list of conditions and the following disclaimer.
1442
* Redistributions in binary form must reproduce the above copyright
1443
notice, this list of conditions and the following disclaimer in the
1444
documentation and/or other materials provided with the distribution.
1446
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1447
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1448
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1449
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1450
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1451
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
1452
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
1453
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
1454
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
1455
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1456
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2266
This module is licenced under the BSD license.
2268
Copyright (C) 2009, 2010, 2011, Taobao Inc., Alibaba Group ( <http://www.taobao.com> ).
2270
Copyright (C) 2009, 2010, 2011, by Xiaozhe Wang (chaoslawful) <chaoslawful@gmail.com>.
2272
Copyright (C) 2009, 2010, 2011, by Zhang "agentzh" Yichun (章亦春) <agentzh@gmail.com>.
2274
All rights reserved.
2276
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
2278
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2280
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
2282
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2287
* [Dynamic Routing Based on Redis and Lua](http://openresty.org/#DynamicRoutingBasedOnRedis)
2288
* [Using LuaRocks with ngx_lua](http://openresty.org/#UsingLuaRocks)
2289
* [Introduction to ngx_lua](https://github.com/chaoslawful/lua-nginx-module/wiki/Introduction)
2290
* [ngx_devel_kit](http://github.com/simpl/ngx_devel_kit)
2291
* [HttpEchoModule](http://wiki.nginx.org/HttpEchoModule)
2292
* [HttpDrizzleModule](http://wiki.nginx.org/HttpDrizzleModule)
2293
* [postgres-nginx-module](http://github.com/FRiCKLE/ngx_postgres)
2294
* [HttpMemcModule](http://wiki.nginx.org/HttpMemcModule)
2295
* [The ngx_openresty bundle](http://openresty.org)