1- # Tarantool NginX upstream module (v2.3.1)
1+ # Tarantool NginX upstream module
22---------------------------------
33Key features:
44* Both nginx and tarantool features accessible over HTTP(S).
@@ -7,14 +7,18 @@ Key features:
77* Backup and fault tolerance.
88* Low overhead.
99
10- Note: WebSockets are currently not supported until Tarantool supports out-of-band replies.
10+ # Limitations
11+ -------------
12+ 1 ) WebSockets are currently not supported until Tarantool supports out-of-band replies.
13+ 2 ) This module does not support tarantool 1.6.x start from 2.4.0. Since it uses
14+ tarantool 1.7 protocol features.
1115
1216About Tarantool: http://tarantool.org
1317
1418About upstream: http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream
1519
1620## Docker images
17-
21+ ----------------
1822Nginx upstream module - https://hub.docker.com/r/tarantool/tarantool-nginx
1923
2024Tarantool - https://hub.docker.com/r/tarantool/tarantool
@@ -26,7 +30,8 @@ Tarantool - https://hub.docker.com/r/tarantool/tarantool
2630* v0.2.1 - Production ready.
2731* v0.2.2 - Stable.
2832* v2.3.1 - Production ready.
29- * v2.3.2 - Production ready.
33+ * v2.3.2 - production ready.
34+ * v2.4.0-beta - Stable, Beta.
3035
3136## Content
3237----------
@@ -35,6 +40,9 @@ Tarantool - https://hub.docker.com/r/tarantool/tarantool
3540* [ JSON] ( #json )
3641* [ Directives] ( #directives )
3742 * [ tnt_pass] ( #tnt_pass )
43+ * [ tnt_eval] ( #tnt_eval )
44+ * [ tnt_eval_buffer_size] ( #tnt_eval_buffer_size )
45+ * [ tnt_eval_subrequest_in_memory] ( #tnt_eval_subrequest_in_memory )
3846 * [ tnt_http_methods] ( #tnt_http_methods )
3947 * [ tnt_http_rest_methods] ( #tnt_http_rest_methods )
4048 * [ tnt_pass_http_request] ( #tnt_pass_http_request )
@@ -198,16 +206,23 @@ end
198206
199207### Output JSON form
200208
209+
201210 [ { "result": JSON_RESULT_OBJECT, "id":UINT, "error": { "message": STR, "code": INT } }, ...N ]
202211
203- "result"
212+
213+ "result" - DEPRICATED in 2.4.0+
214+
215+ Version 2.4.0+ output a raw result, i.e. "JSON_RESULT_OBJECT".
204216
205217 Tarantool execution result (a json object/array, etc).
206218
207219 MAY be null or undefined.
208220
221+
209222 "id"
210223
224+ DEPRICATED in 2.4.0+
225+
211226 Request id is returned back.
212227
213228 MAY be null or undefined.
@@ -223,21 +238,27 @@ end
223238
224239 See "message"/"code" fields for details.
225240
226-
227241### Example
228242
243+ For instance, tarantool has stored procedure
244+ ```Lua
245+ function echo(a, b, c, d)
246+ return a, b, c, d
247+ end
248+ ```
249+
229250 Syntax:
230251
231252 --> data sent to Server
232253 <-- data sent to Client
233254
234255 rpc call 1:
235256 --> { "method": "echo", "params": [42, 23], "id": 1 }
236- <-- { "result": [42, 23], "id": 1 }
257+ <-- [42, 23]
237258
238259 rpc call 2:
239260 --> { "method": "echo", "params": [ [ {"hello": "world"} ], "!" ], "id": 2 }
240- <-- { "result": [ [ {"hello": "world"} ], "!" ], "id": 2 }
261+ <-- [ {"hello": "world"} ], "!" ]
241262
242263 rpc call of a non-existent method:
243264 --> { "method": "echo_2", "id": 1 }
253274 { "method": "echo", "params": [ [ {"hello": "world"} ], "!" ], "id": 2 }
254275 ]
255276 <-- [
256- { "result": [42, 23], "id": 1 } ,
257- { "result": [ [ {"hello": "world"} ], "!" ], "id": 2 }
277+ [42, 23],
278+ [ {"hello": "world"} ], "!" ],
258279 ]
259280
260281 rpc call Batch of a non-existent method:
264285 ]
265286 <-- [
266287 { "error": {"code": -32601, "message": "Method not found"}, "id": 1 },
267- { "result": [ [ {"hello": "world"} ], "!" ], "id": 2 }
288+ [ {"hello": "world"} ], "!" ]
268289 ]
269290
270291 rpc call Batch with invalid JSON:
@@ -291,19 +312,136 @@ tnt_pass
291312Specify the Tarantool server backend.
292313
293314``` nginx
315+
316+ upstream tnt_upstream {
317+ 127.0.0.1:9999
318+ };
319+
294320 location = /tnt {
295321 tnt_pass 127.0.0.1:9999;
296322 }
297323
324+ location = /tnt_next_location {
325+ tnt_pass tnt_upstream;
326+ }
327+ ```
328+
329+ [ Back to content] ( #content )
330+
331+ tnt_eval
332+ ------------
333+ ** syntax:** * tnt_eval $HTTP_STATUS_VAR_NAME $HTTP_BODY_VAR_NAME*
334+
335+ ** default:** * no*
336+
337+ ** context:** * location*
338+
339+ This directive put execution of tnt_pass into the nginx REWRITE PHASE.
340+ That exactly this mean? That means that you can have a access to the body (in for of
341+ JSON), http codes and http headers which have been passed from the Tarantool
342+ to the nginx inside nginx config. This very useful for setting custom HTTP
343+ statuses, headers and for post-processing of the original body.
344+
345+ Even more, you can use this for using this module with OpenResty, Nginx Script,
346+ Nginx Perl and so on.
347+
348+ NOTICE!
349+
350+ 1 ) This directive expects that tarantool returns special object with meta
351+ information about an HTTP status and an HTTP headers.
352+
353+ Example
354+
355+ ``` Lua
356+ # Tarantool , stored procedure
357+ function foo (a )
358+ return
359+ -- First arg. iff __ngx exists and tnt_evan is , then it will be
360+ {
361+ __ngx = {
362+ tonumber (req .args .status_code ) or 200 ,
363+ { [" X-Tarantool" ] = " FROM_TNT" }
364+ }
365+ },
366+ req ,
367+
368+ end
369+ ```
370+
371+ ``` nginx
372+ # Nginx, configuration
373+
298374 upstream tnt_upstream {
299375 127.0.0.1:9999;
300- };
376+ }
301377
302- location = /tnt_next_location {
303- tnt_pass tnt_upstream;
304- }
378+ location = /tnt {
379+
380+ tnt_eval_buffer_size 1m;
381+
382+ tnt_eval $tnt_http_status $tnt_body {
383+ tnt_method foo;
384+ tnt_pass 127.0.0.1:9999;
385+ }
386+
387+ if ($tnt_http_status = 404) {
388+ return 404 $tnt_body;
389+ }
390+
391+ if ($tnt_body ~= 'Tarantool') {
392+ return 200 '<html><h1>Found Tarantool!</h1></html>';
393+ }
394+
395+ return 200 $tnt_body;
396+ }
397+
398+ location = /tnt/with_echo_module {
399+
400+ tnt_eval_buffer_size 1m;
401+
402+ tnt_eval $tnt_http_status $tnt_body {
403+ tnt_method foo;
404+ tnt_pass 127.0.0.1:9999;
405+ }
406+
407+ echo $tnt_body;
408+ }
409+
410+ # ...
411+ # Also those variables are available in any nginx's languages;
305412```
306413
414+ 2 ) '$'-prefix is required as part of names, means tnt_eval http_code body { ... } is error,
415+ it should be tnt_eval $http_status $body { ... }.
416+
417+ 3 ) Limitations. The contents of subrequests issued from within the tnt_eval block
418+ (like those fired by echo_subrequest) won't be captured properly.
419+
420+ [ Back to content] ( #content )
421+
422+ tnt_eval_buffer_size
423+ --------------------
424+
425+ ** syntax:** * tnt_eval_buffer_size size*
426+
427+ ** default:** * PAGE_SIZE x 16*
428+
429+ ** context:** * main, server, location*
430+
431+ Specify the size of the buffer used for ` tnt_eval ` .
432+
433+ [ Back to content] ( #content )
434+
435+ tnt_eval_subrequest_in_memory
436+ -----------------------------
437+ ** syntax:** * tnt_eval_subrequest_in_memory flag*
438+
439+ ** default:** * off*
440+
441+ ** context:** * main, server, location*
442+
443+ Specify that subrequest (i.e. ` tnt_eval ` ) will be executed in memory.
444+
307445[ Back to content] ( #content )
308446
309447tnt_http_methods
@@ -580,15 +718,14 @@ The 0 value turns off this limitation.
580718
581719[ Back to content] ( #content )
582720
583- tnt_pure_result
584- --------------------
721+ tnt_pure_result - DEPRICATED in 2.4.0+
722+ --------------------------------------
585723** syntax:** * tnt_pure_result [ on|off] *
586724
587725** default:** * off*
588726
589727** context:** * http, server, location*
590728
591-
592729Whether to wrap tnt response or not.
593730When this option is off:
594731```
@@ -601,15 +738,14 @@ When this option is on:
601738
602739[ Back to content] ( #content )
603740
604- tnt_multireturn_skip_count
605- --------------------
741+ tnt_multireturn_skip_count - DEPRICATED in 2.4.0+
742+ -------------------------------------------------
606743** syntax:** * tnt_multireturn_skip_count [ 0|1|2] *
607744
608745** default:** * 0*
609746
610747** context:** * http, server, location*
611748
612-
613749Module will skip one or more multireturn parts when this option is > 0
614750When it is set to 0:
615751```
0 commit comments