You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31-27
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ Table of Contents
32
32
Status
33
33
======
34
34
35
-
Producty ready.
35
+
Production ready.
36
36
37
37
Synopsis
38
38
========
@@ -107,7 +107,7 @@ This module is a core component of OpenResty. If you are using this module, then
107
107
This is a port of the [ngx_http_lua_module](https://github.com/openresty/lua-nginx-module#readme) to the NGINX "stream" subsystem so
108
108
as to support generic stream/TCP clients in the downstream.
109
109
110
-
Lua APIs and directive names rename the same as the `ngx_http_lua_module`.
110
+
Lua APIs and directive names remain the same as the `ngx_http_lua_module`.
111
111
112
112
[Back to TOC](#table-of-contents)
113
113
@@ -176,9 +176,9 @@ Acts as a `preread` phase handler and executes Lua code string specified in `lua
176
176
(or packet in datagram mode).
177
177
The Lua code may make [API calls](#nginx-api-for-lua) and is executed as a new spawned coroutine in an independent global environment (i.e. a sandbox).
178
178
179
-
It is possible to acquire raw request socket using [ngx.req.socket](https://github.com/openresty/lua-nginx-module#ngxreqsocket)
179
+
It is possible to acquire the raw request socket using [ngx.req.socket](https://github.com/openresty/lua-nginx-module#ngxreqsocket)
180
180
and receive data from or send data to the client. However, keep in mind that calling the `receive()` method
181
-
of the request socket will consume the data from the buffer and those data will not be seen by handlers
181
+
of the request socket will consume the data from the buffer and such consumed data will not be seen by handlers
182
182
further down the chain.
183
183
184
184
The `preread_by_lua_block` code will always run at the end of the `preread` processing phase unless
@@ -189,7 +189,7 @@ This directive was first introduced in the `v0.0.3` release.
@@ -202,33 +202,33 @@ or LuaJIT bytecode to be executed.
202
202
203
203
Nginx variables can be used in the `<path-to-lua-script-file>` string to provide flexibility. This however carries some risks and is not ordinarily recommended.
204
204
205
-
When a relative path like `foo/bar.lua` is given, they will be turned into the absolute path relative to the `server prefix` path determined by the `-p PATH` command-line option while starting the Nginx server.
205
+
When a relative path like `foo/bar.lua` is given, it will be turned into the absolute path relative to the `server prefix` path determined by the `-p PATH` command-line option given when starting the Nginx server.
206
206
207
-
When the Lua code cache is turned on (by default), the user code is loaded once at the first request and cached and the Nginx config must be reloaded each time the Lua source file is modified. The Lua code cache can be temporarily disabled during development by switching [lua_code_cache](#lua_code_cache)`off` in `nginx.conf` to avoid reloading Nginx.
207
+
When the Lua code cache is turned on (by default), the user code is loaded once at the first connection and cached. The Nginx config must be reloaded each time the Lua source file is modified. The Lua code cache can be temporarily disabled during development by switching [lua_code_cache](#lua_code_cache)`off` in `nginx.conf` to avoid having to reload Nginx.
208
208
209
209
This directive was first introduced in the `v0.0.3` release.
210
210
211
211
[Back to TOC](#directives)
212
212
213
213
log_by_lua_block
214
-
--------------------
214
+
----------------
215
215
216
216
**syntax:***log_by_lua_block { lua-script }*
217
217
218
218
**context:***stream, server*
219
219
220
220
**phase:***log*
221
221
222
-
Runs the Lua source code inlined as the `<lua-script-str>`at the `log` request processing phase. This does not replace the current access logs, but runs before.
222
+
Runs the Lua source code specified as `<lua-script>`during the `log` request processing phase. This does not replace the current access logs, but runs before.
223
223
224
-
Yielding APIs in this phase, such as `ngx.req.socket`, `ngx.socket.*`, `ngx.sleep`, `ngx.say` are **not** available in this phase.
224
+
Yielding APIs such as `ngx.req.socket`, `ngx.socket.*`, `ngx.sleep`, or`ngx.say` are **not** available in this phase.
225
225
226
226
This directive was first introduced in the `v0.0.3` release.
@@ -241,9 +241,9 @@ or LuaJIT bytecode to be executed.
241
241
242
242
Nginx variables can be used in the `<path-to-lua-script-file>` string to provide flexibility. This however carries some risks and is not ordinarily recommended.
243
243
244
-
When a relative path like `foo/bar.lua` is given, they will be turned into the absolute path relative to the `server prefix` path determined by the `-p PATH` command-line option while starting the Nginx server.
244
+
When a relative path like `foo/bar.lua` is given, it will be turned into the absolute path relative to the `server prefix` path determined by the `-p PATH` command-line option given when starting the Nginx server.
245
245
246
-
When the Lua code cache is turned on (by default), the user code is loaded once at the first request and cached and the Nginx config must be reloaded each time the Lua source file is modified. The Lua code cache can be temporarily disabled during development by switching [lua_code_cache](#lua_code_cache)`off` in `nginx.conf` to avoid reloading Nginx.
246
+
When the Lua code cache is turned on (by default), the user code is loaded once at the first connection and cached. The Nginx config must be reloaded each time the Lua source file is modified. The Lua code cache can be temporarily disabled during development by switching [lua_code_cache](#lua_code_cache)`off` in `nginx.conf` to avoid having to reload Nginx.
247
247
248
248
This directive was first introduced in the `v0.0.3` release.
249
249
@@ -256,11 +256,11 @@ lua_add_variable
256
256
257
257
**context:***stream*
258
258
259
-
Add variable `$var` to the stream subsystem and makes it changeable. If `$var` already exists,
259
+
Add the variable `$var` to the stream subsystem and makes it changeable. If `$var` already exists,
260
260
this directive will do nothing.
261
261
262
262
By default, variables added using this directive are considered "not found" and reading them
263
-
using `ngx.var` will return `nil`. However, they could be re-assigned using `ngx.var` code at any time.
263
+
using `ngx.var` will return `nil`. However, they could be re-assigned via the `ngx.var.VARIABLE` API at any time.
264
264
265
265
This directive was first introduced in the `v0.0.4` release.
266
266
@@ -308,16 +308,17 @@ is ignored and the raw request socket is always returned. Unlike `ngx_http_lua_m
308
308
you can still call output API functions like `ngx.say`, `ngx.print`, and `ngx.flush`
309
309
after acquiring the raw request socket via this function.
310
310
311
-
When stream server is in UDP mode, reading from the downstream socket returned by the
311
+
When the stream server is in UDP mode, reading from the downstream socket returned by the
312
312
`ngx.req.socket` call will only return the content of a single packet. Therefore
313
313
the reading call will never block and will return `nil, "no more data"` when all the
314
314
data from the datagram has been consumed. However, you may choose to send multiple UDP
315
315
packets back to the client using the downstream socket.
316
316
317
-
Raw TCP request socket returned by this module will contain the following extra method:
317
+
The raw TCP sockets returned by this module will contain the following extra method:
318
318
319
319
tcpsock:shutdown
320
320
----------------
321
+
321
322
**syntax:***ok, err = tcpsock:shutdown("send")*
322
323
323
324
**context:***content_by_lua**
@@ -333,15 +334,15 @@ before calling this method, consider use `ngx.flush(true)` to make sure all busy
333
334
flushed before shutting down the socket. If any busy buffers were detected, this method will return `nil`
334
335
will error message `"socket busy writing"`.
335
336
336
-
This feature is particularly useful for protocols that generates response before actually
337
-
finishes consuming all incoming data. Normally Kernel will send out RST to the client when
337
+
This feature is particularly useful for protocols that generate a response before actually
338
+
finishing consuming all incoming data. Normally, the kernel will send RST to the client when
338
339
[tcpsock:close](https://github.com/openresty/lua-nginx-module#tcpsockclose) is called without
339
340
emptying the receiving buffer first. Calling this method will allow you to keep reading from
340
341
the receiving buffer and prevents RST from being sent.
341
342
342
343
You can also use this method to simulate lingering close similar to that
343
344
[provided by the ngx_http_core_module](https://nginx.org/en/docs/http/ngx_http_core_module.html#lingering_close)
344
-
for protocols that needs such behavior. Here is an example:
345
+
for protocols in need of such behavior. Here is an example:
345
346
346
347
```lua
347
348
localLINGERING_TIME=30-- 30 seconds
@@ -366,19 +367,20 @@ until (not data and not partial) or ngx.time() >= deadline
366
367
367
368
reqsock:peek
368
369
------------
370
+
369
371
**syntax:***ok, err = reqsock:peek(size)*
370
372
371
373
**context:***preread_by_lua**
372
374
373
375
Peeks into the [preread](https://nginx.org/en/docs/stream/stream_processing.html#preread_phase)
374
376
buffer that contains downstream data sent by the client without consuming them.
375
-
That is, data returned by this API will still be forwarded to upstream in later phases.
377
+
That is, data returned by this API will still be forwarded upstream in later phases.
376
378
377
379
This function takes a single required argument, `size`, which is the number of bytes to be peeked.
378
380
Repeated calls to this function always returns data from the beginning of the preread buffer.
379
381
380
-
Note that preread phase happens after TLS handshake. If the stream server was configured with
381
-
TLS enabled, data returned will be in clear text.
382
+
Note that preread phase happens after the TLS handshake. If the stream server was configured with
383
+
TLS enabled, the returned data will be in clear text.
382
384
383
385
If preread buffer does not have the requested amount of data, then the current Lua thread will
384
386
be yielded until more data is available, [`preread_buffer_size`](https://nginx.org/en/docs/stream/ngx_stream_core_module.html#preread_buffer_size)
@@ -398,9 +400,9 @@ the current stream session will be terminated with the
398
400
In both cases, no further processing on the session is possible (except `log_by_lua*`). The connection will be closed by the
399
401
stream core module automatically.
400
402
401
-
Note that this API can not be used if consumption of client data has occurred. For example, after calling
402
-
`reqsock:receive`. If such attempt was made, Lua error `"attempt to peek on a consumed socket"` will
403
-
be thrown. Consuming client data after calling this API safe and allowed.
403
+
Note that this API cannot be used if consumption of client data has occurred. For example, after calling
404
+
`reqsock:receive`. If such an attempt was made, the Lua error `"attempt to peek on a consumed socket"` will
405
+
be thrown. Consuming client data after calling this API is allowed and safe.
404
406
405
407
Here is an example of using this API:
406
408
@@ -503,7 +505,9 @@ Nginx Compatibility
503
505
504
506
The latest version of this module is compatible with the following versions of Nginx:
505
507
506
-
* 1.13.x >= 1.13.6
508
+
* 1.17.x (last tested: 1.17.1)
509
+
* 1.15.x (last tested: 1.15.8)
510
+
* 1.13.x (last tested: 1.13.6)
507
511
508
512
Nginx cores older than 1.13.6 (exclusive) are *not* tested and may or may not work. Use at your own risk!
0 commit comments