Skip to content

Commit 3080236

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 644d4a6 + 59b6430 commit 3080236

File tree

76 files changed

+7026
-954
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+7026
-954
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ test/blib
2626
test.sh
2727
t.sh
2828
t/t.sh
29+
t/servroot*
2930
test/t/servroot/
3031
releng
3132
reset

.travis.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
sudo: required
2-
dist: trusty
2+
dist: xenial
33

44
os: linux
55

@@ -48,10 +48,9 @@ env:
4848
- DRIZZLE_VER=2011.07.21
4949
- TEST_NGINX_SLEEP=0.006
5050
matrix:
51-
- NGINX_VERSION=1.13.6 OPENSSL_VER=1.0.2n OPENSSL_OPT="" OPENSSL_PATCH_VER=1.0.2h
52-
- NGINX_VERSION=1.13.6 OPENSSL_VER=1.1.0h OPENSSL_OPT="" OPENSSL_PATCH_VER=1.1.0d
53-
# TODO: when adding an OpenSSL version >= 1.1.1, please add "enable-tls1_3"
54-
# to $OPENSSL_OPT.
51+
- NGINX_VERSION=1.15.8 OPENSSL_VER=1.0.2s OPENSSL_PATCH_VER=1.0.2h
52+
- NGINX_VERSION=1.15.8 OPENSSL_VER=1.1.0k OPENSSL_PATCH_VER=1.1.0d
53+
- NGINX_VERSION=1.15.8 OPENSSL_VER=1.1.1c OPENSSL_PATCH_VER=""
5554

5655
services:
5756
- memcache
@@ -96,6 +95,8 @@ before_script:
9695

9796
script:
9897
- sudo iptables -I OUTPUT 1 -p udp --dport 10086 -j REJECT
98+
- sudo iptables -A OUTPUT -p tcp --dst 127.0.0.2 --dport 12345 -j DROP
99+
- sudo iptables -A OUTPUT -p udp --dst 127.0.0.2 --dport 12345 -j DROP
99100
- cd luajit2/
100101
- make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT -msse4.2' > build.log 2>&1 || (cat build.log && exit 1)
101102
- sudo make install PREFIX=$LUAJIT_PREFIX > build.log 2>&1 || (cat build.log && exit 1)
@@ -114,8 +115,8 @@ script:
114115
- cd ..
115116
- tar zxf download-cache/openssl-$OPENSSL_VER.tar.gz
116117
- cd openssl-$OPENSSL_VER/
117-
- patch -p1 < ../../openresty/patches/openssl-$OPENSSL_PATCH_VER-sess_set_get_cb_yield.patch
118-
- ./config no-threads shared enable-ssl3 enable-ssl3-method $OPENSSL_OPT -g --prefix=$OPENSSL_PREFIX -DPURIFY > build.log 2>&1 || (cat build.log && exit 1)
118+
- if [ -n "$OPENSSL_PATCH_VER" ]; then patch -p1 < ../../openresty/patches/openssl-$OPENSSL_PATCH_VER-sess_set_get_cb_yield.patch; fi
119+
- ./config no-threads shared enable-ssl3 enable-ssl3-method -g --prefix=$OPENSSL_PREFIX -DPURIFY > build.log 2>&1 || (cat build.log && exit 1)
119120
- make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1)
120121
- sudo make PATH=$PATH install_sw > build.log 2>&1 || (cat build.log && exit 1)
121122
- cd ..

README.markdown

Lines changed: 133 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Name
88

99
ngx_http_lua_module - Embed the power of Lua into Nginx HTTP Servers.
1010

11+
This module is a core component of OpenResty. If you are using this module, then you are essentially using OpenResty :)
12+
1113
*This module is not distributed with the Nginx source.* See [the installation instructions](#installation).
1214

1315
Table of Contents
@@ -61,7 +63,7 @@ Production ready.
6163
Version
6264
=======
6365

64-
This document describes ngx_lua [v0.10.13](https://github.com/openresty/lua-nginx-module/tags) released on 22 April 2018.
66+
This document describes ngx_lua [v0.10.15](https://github.com/openresty/lua-nginx-module/tags) released on March 14th, 2019.
6567

6668
Synopsis
6769
========
@@ -186,6 +188,8 @@ Synopsis
186188
Description
187189
===========
188190

191+
This module is a core component of OpenResty. If you are using this module, then you are essentially using OpenResty :)
192+
189193
This module embeds Lua, via [LuaJIT 2.0/2.1](http://luajit.org/luajit.html), into Nginx and by leveraging Nginx's subrequests, allows the integration of the powerful Lua threads (Lua coroutines) into the Nginx event model.
190194

191195
Unlike [Apache's mod_lua](https://httpd.apache.org/docs/trunk/mod/mod_lua.html) and [Lighttpd's mod_magnet](http://redmine.lighttpd.net/wiki/1/Docs:ModMagnet), Lua code executed using this module can be *100% non-blocking* on network traffic as long as the [Nginx API for Lua](#nginx-api-for-lua) provided by this module is used to handle
@@ -248,6 +252,8 @@ Nginx Compatibility
248252

249253
The latest version of this module is compatible with the following versions of Nginx:
250254

255+
* 1.15.x (last tested: 1.15.8)
256+
* 1.14.x
251257
* 1.13.x (last tested: 1.13.6)
252258
* 1.12.x
253259
* 1.11.x (last tested: 1.11.2)
@@ -956,7 +962,7 @@ This module is licensed under the BSD license.
956962

957963
Copyright (C) 2009-2017, by Xiaozhe Wang (chaoslawful) <chaoslawful@gmail.com>.
958964

959-
Copyright (C) 2009-2018, by Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>, OpenResty Inc.
965+
Copyright (C) 2009-2019, by Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>, OpenResty Inc.
960966

961967
All rights reserved.
962968

@@ -1000,6 +1006,7 @@ See Also
10001006
Directives
10011007
==========
10021008

1009+
* [lua_load_resty_core](#lua_load_resty_core)
10031010
* [lua_capture_error_log](#lua_capture_error_log)
10041011
* [lua_use_default_type](#lua_use_default_type)
10051012
* [lua_malloc_trim](#lua_malloc_trim)
@@ -1065,6 +1072,7 @@ Directives
10651072
* [lua_check_client_abort](#lua_check_client_abort)
10661073
* [lua_max_pending_timers](#lua_max_pending_timers)
10671074
* [lua_max_running_timers](#lua_max_running_timers)
1075+
* [lua_sa_restart](#lua_sa_restart)
10681076

10691077

10701078
The basic building blocks of scripting Nginx with Lua are directives. Directives are used to specify when the user Lua code is run and
@@ -1074,6 +1082,38 @@ how the result will be used. Below is a diagram showing the order in which direc
10741082

10751083
[Back to TOC](#table-of-contents)
10761084

1085+
lua_load_resty_core
1086+
-------------------
1087+
1088+
**syntax:** *lua_load_resty_core on|off*
1089+
1090+
**default:** *lua_load_resty_core on*
1091+
1092+
**context:** *http*
1093+
1094+
Controls whether the `resty.core` module (from
1095+
[lua-resty-core](https://github.com/openresty/lua-resty-core)) should be loaded
1096+
or not. When enabled, this directive is equivalent to executing the following
1097+
when the Lua VM is created:
1098+
1099+
```lua
1100+
1101+
require "resty.core"
1102+
```
1103+
1104+
Note that usage of the `resty.core` module is recommended, as its
1105+
FFI implementation is both faster, safer, and more complete than the Lua C API
1106+
of the ngx_lua module.
1107+
1108+
It must also be noted that the Lua C API of the ngx_lua module will eventually
1109+
be removed, and usage of the FFI-based API (i.e. the `resty.core`
1110+
module) will become mandatory. This directive only aims at providing a
1111+
temporary backwards-compatibility mode in case of edge-cases.
1112+
1113+
This directive was first introduced in the `v0.10.15` release.
1114+
1115+
[Back to TOC](#directives)
1116+
10771117
lua_capture_error_log
10781118
---------------------
10791119
**syntax:** *lua_capture_error_log size*
@@ -2583,15 +2623,18 @@ But do not forget to comment this line out before publishing your site to the wo
25832623
If you are using the [official pre-built packages](http://openresty.org/en/linux-packages.html) for [OpenResty](https://openresty.org/)
25842624
1.11.2.1 or later, then everything should work out of the box.
25852625

2586-
If you are using OpenSSL libraries not provided by [OpenResty](https://openresty.org),
2587-
then you need to apply the following patch for OpenSSL 1.0.2h or later:
2626+
If you are not using one of the [OpenSSL
2627+
packages](https://openresty.org/en/linux-packages.html) provided by
2628+
[OpenResty](https://openresty.org), you will need to apply patches to OpenSSL
2629+
1.0.2, up to (and including) 1.1.0:
25882630

2589-
<https://github.com/openresty/openresty/blob/master/patches/openssl-1.0.2h-sess_set_get_cb_yield.patch>
2631+
<https://openresty.org/en/openssl-patches.html>
25902632

2591-
If you are not using the NGINX core shipped with [OpenResty](https://openresty.org) 1.11.2.1 or later, then you need to
2592-
apply the following patch to the standard NGINX core 1.11.2 or later:
2633+
Similarly, if you are not using the NGINX core shipped with
2634+
[OpenResty](https://openresty.org) 1.11.2.1 or later, you will need to apply
2635+
patches to the standard NGINX core:
25932636

2594-
<http://openresty.org/download/nginx-1.11.2-nonblocking_ssl_handshake_hooks.patch>
2637+
<https://openresty.org/en/nginx-ssl-patches.html>
25952638

25962639
This directive was first introduced in the `v0.10.6` release.
25972640

@@ -3069,6 +3112,23 @@ This directive was first introduced in the `v0.8.0` release.
30693112

30703113
[Back to TOC](#directives)
30713114

3115+
lua_sa_restart
3116+
--------------
3117+
3118+
**syntax:** *lua_sa_restart on|off*
3119+
3120+
**default:** *lua_sa_restart on*
3121+
3122+
**context:** *http*
3123+
3124+
When enabled, this module will set the `SA_RESTART` flag on nginx workers signal dispositions.
3125+
3126+
This allows Lua I/O primitives to not be interrupted by nginx's handling of various signals.
3127+
3128+
This directive was first introduced in the `v0.10.14` release.
3129+
3130+
[Back to TOC](#directives)
3131+
30723132
Nginx API for Lua
30733133
=================
30743134

@@ -4264,7 +4324,7 @@ ngx.req.get_method
42644324
------------------
42654325
**syntax:** *method_name = ngx.req.get_method()*
42664326

4267-
**context:** *set_by_lua&#42;, rewrite_by_lua&#42;, access_by_lua&#42;, content_by_lua&#42;, header_filter_by_lua&#42;, balancer_by_lua&#42;*
4327+
**context:** *set_by_lua&#42;, rewrite_by_lua&#42;, access_by_lua&#42;, content_by_lua&#42;, header_filter_by_lua&#42;, body_filter_by_lua&#42;, balancer_by_lua&#42;, log_by_lua&#42;*
42684328

42694329
Retrieves the current request's request method name. Strings like `"GET"` and `"POST"` are returned instead of numerical [method constants](#http-method-constants).
42704330

@@ -6683,7 +6743,7 @@ ngx.shared.DICT.flush_expired
66836743

66846744
Flushes out the expired items in the dictionary, up to the maximal number specified by the optional `max_count` argument. When the `max_count` argument is given `0` or not given at all, then it means unlimited. Returns the number of items that have actually been flushed.
66856745

6686-
Unlike the [flush_all](#ngxshareddictflush_all) method, this method actually free up the memory used by the expired items.
6746+
Unlike the [flush_all](#ngxshareddictflush_all) method, this method actually frees up the memory used by the expired items.
66876747

66886748
This feature was first introduced in the `v0.6.3` release.
66896749

@@ -7073,6 +7133,43 @@ An optional Lua table can be specified as the last argument to this method to sp
70737133
* `pool`
70747134
specify a custom name for the connection pool being used. If omitted, then the connection pool name will be generated from the string template `"<host>:<port>"` or `"<unix-socket-path>"`.
70757135

7136+
* `pool_size`
7137+
specify the size of the connection pool. If omitted and no
7138+
`backlog` option was provided, no pool will be created. If omitted
7139+
but `backlog` was provided, the pool will be created with a default
7140+
size equal to the value of the [lua_socket_pool_size](#lua_socket_pool_size)
7141+
directive.
7142+
The connection pool holds up to `pool_size` alive connections
7143+
ready to be reused by subsequent calls to [connect](#tcpsockconnect), but
7144+
note that there is no upper limit to the total number of opened connections
7145+
outside of the pool. If you need to restrict the total number of opened
7146+
connections, specify the `backlog` option.
7147+
When the connection pool would exceed its size limit, the least recently used
7148+
(kept-alive) connection already in the pool will be closed to make room for
7149+
the current connection.
7150+
Note that the cosocket connection pool is per Nginx worker process rather
7151+
than per Nginx server instance, so the size limit specified here also applies
7152+
to every single Nginx worker process. Also note that the size of the connection
7153+
pool cannot be changed once it has been created.
7154+
This option was first introduced in the `v0.10.14` release.
7155+
7156+
* `backlog`
7157+
if specified, this module will limit the total number of opened connections
7158+
for this pool. No more connections than `pool_size` can be opened
7159+
for this pool at any time. If the connection pool is full, subsequent
7160+
connect operations will be queued into a queue equal to this option's
7161+
value (the "backlog" queue).
7162+
If the number of queued connect operations is equal to `backlog`,
7163+
subsequent connect operations will fail and return `nil` plus the
7164+
error string `"too many waiting connect operations"`.
7165+
The queued connect operations will be resumed once the number of connections
7166+
in the pool is less than `pool_size`.
7167+
The queued connect operation will abort once they have been queued for more
7168+
than `connect_timeout`, controlled by
7169+
[settimeouts](#tcpsocksettimeouts), and will return `nil` plus
7170+
the error string `"timeout"`.
7171+
This option was first introduced in the `v0.10.14` release.
7172+
70767173
The support for the options table argument was first introduced in the `v0.5.7` release.
70777174

70787175
This method was first introduced in the `v0.5.0rc1` release.
@@ -7218,7 +7315,7 @@ Timeout for the reading operation is controlled by the [lua_socket_read_timeout]
72187315
```lua
72197316

72207317
sock:settimeouts(1000, 1000, 1000) -- one second timeout for connect/read/write
7221-
local data, err = sock:receiveany(10 * 1024 * 1024) -- read any data, at most 10K
7318+
local data, err = sock:receiveany(10 * 1024) -- read any data, at most 10K
72227319
if not data then
72237320
ngx.say("failed to read any data: ", err)
72247321
return
@@ -7404,13 +7501,31 @@ Puts the current socket's connection immediately into the cosocket built-in conn
74047501

74057502
The first optional argument, `timeout`, can be used to specify the maximal idle timeout (in milliseconds) for the current connection. If omitted, the default setting in the [lua_socket_keepalive_timeout](#lua_socket_keepalive_timeout) config directive will be used. If the `0` value is given, then the timeout interval is unlimited.
74067503

7407-
The second optional argument, `size`, can be used to specify the maximal number of connections allowed in the connection pool for the current server (i.e., the current host-port pair or the unix domain socket file path). Note that the size of the connection pool cannot be changed once the pool is created. When this argument is omitted, the default setting in the [lua_socket_pool_size](#lua_socket_pool_size) config directive will be used.
7408-
7409-
When the connection pool exceeds the available size limit, the least recently used (idle) connection already in the pool will be closed to make room for the current connection.
7410-
7411-
Note that the cosocket connection pool is per Nginx worker process rather than per Nginx server instance, so the size limit specified here also applies to every single Nginx worker process.
7412-
7413-
Idle connections in the pool will be monitored for any exceptional events like connection abortion or unexpected incoming data on the line, in which cases the connection in question will be closed and removed from the pool.
7504+
The second optional argument `size` is considered deprecated since
7505+
the `v0.10.14` release of this module, in favor of the
7506+
`pool_size` option of the [connect](#tcpsockconnect) method.
7507+
Since the `v0.10.14` release, this option will only take effect if
7508+
the call to [connect](#tcpsockconnect) did not already create a connection
7509+
pool.
7510+
When this option takes effect (no connection pool was previously created by
7511+
[connect](#tcpsockconnect)), it will specify the size of the connection pool,
7512+
and create it.
7513+
If omitted (and no pool was previously created), the default size is the value
7514+
of the [lua_socket_pool_size](#lua_socket_pool_size) directive.
7515+
The connection pool holds up to `size` alive connections ready to be
7516+
reused by subsequent calls to [connect](#tcpsockconnect), but note that there
7517+
is no upper limit to the total number of opened connections outside of the
7518+
pool.
7519+
When the connection pool would exceed its size limit, the least recently used
7520+
(kept-alive) connection already in the pool will be closed to make room for
7521+
the current connection.
7522+
Note that the cosocket connection pool is per Nginx worker process rather
7523+
than per Nginx server instance, so the size limit specified here also applies
7524+
to every single Nginx worker process. Also note that the size of the connection
7525+
pool cannot be changed once it has been created.
7526+
If you need to restrict the total number of opened connections, specify both
7527+
the `pool_size` and `backlog` option in the call to
7528+
[connect](#tcpsockconnect).
74147529

74157530
In case of success, this method returns `1`; otherwise, it returns `nil` and a string describing the error.
74167531

config

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ HTTP_LUA_SRCS=" \
362362
$ngx_addon_dir/src/ngx_http_lua_ssl.c \
363363
$ngx_addon_dir/src/ngx_http_lua_log_ringbuf.c \
364364
$ngx_addon_dir/src/ngx_http_lua_input_filters.c \
365+
$ngx_addon_dir/src/ngx_http_lua_pipe.c \
365366
"
366367

367368
HTTP_LUA_DEPS=" \
@@ -424,6 +425,7 @@ HTTP_LUA_DEPS=" \
424425
$ngx_addon_dir/src/ngx_http_lua_ssl.h \
425426
$ngx_addon_dir/src/ngx_http_lua_log_ringbuf.h \
426427
$ngx_addon_dir/src/ngx_http_lua_input_filters.h \
428+
$ngx_addon_dir/src/ngx_http_lua_pipe.h \
427429
"
428430

429431
CFLAGS="$CFLAGS -DNDK_SET_VAR"
@@ -476,6 +478,17 @@ ngx_feature_test='setsockopt(1, SOL_SOCKET, SO_PASSCRED, NULL, 0);'
476478

477479
. auto/feature
478480

481+
ngx_feature="SA_RESTART"
482+
ngx_feature_libs=
483+
ngx_feature_name="NGX_HTTP_LUA_HAVE_SA_RESTART"
484+
ngx_feature_run=no
485+
ngx_feature_incs="#include <signal.h>"
486+
ngx_feature_path=
487+
ngx_feature_test='struct sigaction act;
488+
act.sa_flags |= SA_RESTART;'
489+
490+
. auto/feature
491+
479492
ngx_feature="__attribute__(constructor)"
480493
ngx_feature_libs=
481494
ngx_feature_name="NGX_HTTP_LUA_HAVE_CONSTRUCTOR"
@@ -514,6 +527,51 @@ CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
514527

515528
# ----------------------------------------
516529

530+
ngx_feature="pipe2"
531+
ngx_feature_libs=
532+
ngx_feature_name="NGX_HTTP_LUA_HAVE_PIPE2"
533+
ngx_feature_run=no
534+
ngx_feature_incs="#include <fcntl.h>"
535+
ngx_feature_test="int fd[2]; pipe2(fd, O_CLOEXEC|O_NONBLOCK);"
536+
SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
537+
CC_TEST_FLAGS="-Werror -Wall $CC_TEST_FLAGS"
538+
539+
. auto/feature
540+
541+
CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
542+
543+
# ----------------------------------------
544+
545+
ngx_feature="signalfd"
546+
ngx_feature_libs=
547+
ngx_feature_name="NGX_HTTP_LUA_HAVE_SIGNALFD"
548+
ngx_feature_run=no
549+
ngx_feature_incs="#include <sys/signalfd.h>"
550+
ngx_feature_test="sigset_t set; signalfd(-1, &set, SFD_NONBLOCK|SFD_CLOEXEC);"
551+
SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
552+
CC_TEST_FLAGS="-Werror -Wall $CC_TEST_FLAGS"
553+
554+
. auto/feature
555+
556+
CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
557+
558+
# ----------------------------------------
559+
560+
ngx_feature="execvpe"
561+
ngx_feature_libs=
562+
ngx_feature_name="NGX_HTTP_LUA_HAVE_EXECVPE"
563+
ngx_feature_run=no
564+
ngx_feature_incs=
565+
ngx_feature_test='char* argv[] = {"/bin/sh"};execvpe("/bin/sh", argv, NULL);'
566+
SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
567+
CC_TEST_FLAGS="-Werror -Wall $CC_TEST_FLAGS"
568+
569+
. auto/feature
570+
571+
CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
572+
573+
# ----------------------------------------
574+
517575
if test -n "$ngx_module_link"; then
518576
ngx_module_type=HTTP_AUX_FILTER
519577
ngx_module_name=$ngx_addon_name

0 commit comments

Comments
 (0)