Coder Social home page Coder Social logo

stream-lua-nginx-module's Introduction

Name

ngx_stream_lua_module - Embed the power of Lua into Nginx stream/TCP Servers.

This module is a core component of OpenResty. If you are using this module, then you are essentially using OpenResty.

This module is not distributed with the Nginx source. See the installation instructions.

Table of Contents

Status

Production ready.

Version

This document describes ngx_stream_lua v0.0.13, which was released on 21 May, 2023.

Synopsis

events {
    worker_connections 1024;
}

stream {
    # define a TCP server listening on the port 1234:
    server {
        listen 1234;

        content_by_lua_block {
            ngx.say("Hello, Lua!")
        }
    }
}

Set up as an SSL TCP server:

stream {
    server {
        listen 4343 ssl;

        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
        ssl_certificate     /path/to/cert.pem;
        ssl_certificate_key /path/to/cert.key;
        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 10m;

        content_by_lua_block {
            local sock = assert(ngx.req.socket(true))
            local data = sock:receive()  -- read a line from downstream
            if data == "thunder!" then
                ngx.say("flash!")  -- output data
            else
                ngx.say("boom!")
            end
            ngx.say("the end...")
        }
    }
}

Listening on a UNIX domain socket is also supported:

stream {
    server {
        listen unix:/tmp/nginx.sock;

        content_by_lua_block {
            ngx.say("What's up?")
            ngx.flush(true)  -- flush any pending output and wait
            ngx.sleep(3)  -- sleeping for 3 sec
            ngx.say("Bye bye...")
        }
    }
}

Back to TOC

Description

This is a port of the ngx_http_lua_module to the Nginx "stream" subsystem so as to support generic stream/TCP clients.

The available Lua APIs and Nginx directives remain the same as those of the ngx_http_lua module.

Back to TOC

Directives

The following directives are ported directly from ngx_http_lua. Please check the documentation of ngx_http_lua for more details about their usage and behavior.

The send_timeout directive in the Nginx "http" subsystem is missing in the "stream" subsystem. As such, ngx_stream_lua_module uses the lua_socket_send_timeout directive for this purpose instead.

Note: the lingering close directive that used to exist in older version of stream_lua_nginx_module has been removed and can now be simulated with the newly added tcpsock:shutdown API if necessary.

Back to TOC

preread_by_lua_block

syntax: preread_by_lua_block { lua-script }

context: stream, server

phase: preread

Acts as a preread phase handler and executes Lua code string specified in lua-script for every connection (or packet in datagram mode). The Lua code may make API calls and is executed as a new spawned coroutine in an independent global environment (i.e. a sandbox).

It is possible to acquire the raw request socket using ngx.req.socket and receive data from or send data to the client. However, keep in mind that calling the receive() method of the request socket will consume the data from the buffer and such consumed data will not be seen by handlers further down the chain.

The preread_by_lua_block code will always run at the end of the preread processing phase unless preread_by_lua_no_postpone is turned on.

This directive was first introduced in the v0.0.3 release.

Back to TOC

preread_by_lua_file

syntax: preread_by_lua_file <path-to-lua-script-file>

context: stream, server

phase: preread

Equivalent to preread_by_lua_block, except that the file specified by <path-to-lua-script-file> contains the Lua code or LuaJIT bytecode to be executed.

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.

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.

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 off in nginx.conf to avoid having to reload Nginx.

This directive was first introduced in the v0.0.3 release.

Back to TOC

log_by_lua_block

syntax: log_by_lua_block { lua-script }

context: stream, server

phase: log

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.

Yielding APIs such as ngx.req.socket, ngx.socket.*, ngx.sleep, or ngx.say are not available in this phase.

This directive was first introduced in the v0.0.3 release.

Back to TOC

log_by_lua_file

syntax: log_by_lua_file <path-to-lua-script-file>

context: stream, server

phase: log

Equivalent to log_by_lua_block, except that the file specified by <path-to-lua-script-file> contains the Lua code or LuaJIT bytecode to be executed.

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.

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.

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 off in nginx.conf to avoid having to reload Nginx.

This directive was first introduced in the v0.0.3 release.

Back to TOC

lua_add_variable

syntax: lua_add_variable $var

context: stream

Add the variable $var to the "stream" subsystem and makes it changeable. If $var already exists, this directive will do nothing.

By default, variables added using this directive are considered "not found" and reading them using ngx.var will return nil. However, they could be re-assigned via the ngx.var.VARIABLE API at any time.

This directive was first introduced in the v0.0.4 release.

Back to TOC

preread_by_lua_no_postpone

syntax: preread_by_lua_no_postpone on|off

context: stream

Controls whether or not to disable postponing preread_by_lua* directives to run at the end of the preread processing phase. By default, this directive is turned off and the Lua code is postponed to run at the end of the preread phase.

This directive was first introduced in the v0.0.4 release.

Back to TOC

Nginx API for Lua

Many Lua API functions are ported from ngx_http_lua. Check out the official manual of ngx_http_lua for more details on these Lua API functions.

This module fully supports the new variable subsystem inside the Nginx stream core. You may access any built-in variables provided by the stream core or other stream modules.

Only raw request sockets are supported, for obvious reasons. The raw argument value is ignored and the raw request socket is always returned. Unlike ngx_http_lua, you can still call output API functions like ngx.say, ngx.print, and ngx.flush after acquiring the raw request socket via this function.

When the stream server is in UDP mode, reading from the downstream socket returned by the ngx.req.socket call will only return the content of a single packet. Therefore the reading call will never block and will return nil, "no more data" when all the data from the datagram has been consumed. However, you may choose to send multiple UDP packets back to the client using the downstream socket.

The raw TCP sockets returned by this module will contain the following extra method:

Back to TOC

reqsock:receiveany

syntax: data, err = reqsock:receiveany(max)

context: content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*

This method is similar to tcpsock:receiveany method

This method was introduced into stream-lua-nginx-module since v0.0.8.

Back to TOC

tcpsock:shutdown

syntax: ok, err = tcpsock:shutdown("send")

context: content_by_lua*

Shuts down the write part of the request socket, prevents all further writing to the client and sends TCP FIN, while keeping the reading half open.

Currently only the "send" direction is supported. Using any parameters other than "send" will return an error.

If you called any output functions (like ngx.say) before calling this method, consider use ngx.flush(true) to make sure all busy buffers are complely flushed before shutting down the socket. If any busy buffers were detected, this method will return nil will error message "socket busy writing".

This feature is particularly useful for protocols that generate a response before actually finishing consuming all incoming data. Normally, the kernel will send RST to the client when tcpsock:close is called without emptying the receiving buffer first. Calling this method will allow you to keep reading from the receiving buffer and prevents RST from being sent.

You can also use this method to simulate lingering close similar to that provided by the ngx_http_core_module for protocols in need of such behavior. Here is an example:

local LINGERING_TIME = 30 -- 30 seconds
local LINGERING_TIMEOUT = 5000 -- 5 seconds

local ok, err = sock:shutdown("send")
if not ok then
    ngx.log(ngx.ERR, "failed to shutdown: ", err)
    return
end

local deadline = ngx.time() + LINGERING_TIME

sock:settimeouts(nil, nil, LINGERING_TIMEOUT)

repeat
    local data, _, partial = sock:receive(1024)
until (not data and not partial) or ngx.time() >= deadline

Back to TOC

reqsock:peek

syntax: ok, err = reqsock:peek(size)

context: preread_by_lua*

Peeks into the preread buffer that contains downstream data sent by the client without consuming them. That is, data returned by this API will still be forwarded upstream in later phases.

This function takes a single required argument, size, which is the number of bytes to be peeked. Repeated calls to this function always returns data from the beginning of the preread buffer.

Note that preread phase happens after the TLS handshake. If the stream server was configured with TLS enabled, the returned data will be in clear text.

If preread buffer does not have the requested amount of data, then the current Lua thread will be yielded until more data is available, preread_buffer_size has been exceeded, or preread_timeout has elapsed. Successful calls always return the requested amounts of data, that is, no partial data will be returned.

When preread_buffer_size has been exceeded, the current stream session will be terminated with the session status code 400 immediately by the stream core module, with error message "preread buffer full" that will be printed to the error log.

When preread_timeout has been exceeded, the current stream session will be terminated with the session status code 200 immediately by the stream core module.

In both cases, no further processing on the session is possible (except log_by_lua*). The connection will be closed by the stream core module automatically.

Note that this API cannot be used if consumption of client data has occurred. For example, after calling reqsock:receive. If such an attempt was made, the Lua error "attempt to peek on a consumed socket" will be thrown. Consuming client data after calling this API is allowed and safe.

Here is an example of using this API:

local sock = assert(ngx.req.socket())

local data = assert(sock:peek(1)) -- peek the first 1 byte that contains the length
data = string.byte(data)

data = assert(sock:peek(data + 1)) -- peek the length + the size byte

local payload = data:sub(2) -- trim the length byte to get actual payload

ngx.log(ngx.INFO, "payload is: ", payload)

This API was first introduced in the v0.0.6 release.

Back to TOC

Back to TOC

TODO

  • Add new directives access_by_lua_block and access_by_lua_file.
  • Add lua_postpone_output to emulate the postpone_output directive.

Back to TOC

Nginx Compatibility

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

  • 1.25.x (last tested: 1.25.1)
  • 1.21.x (last tested: 1.21.4)
  • 1.19.x (last tested: 1.19.3)
  • 1.17.x (last tested: 1.17.8)
  • 1.15.x (last tested: 1.15.8)
  • 1.13.x (last tested: 1.13.6)

Nginx cores older than 1.13.6 (exclusive) are not tested and may or may not work. Use at your own risk!

Back to TOC

Installation

It is highly recommended to use OpenResty releases which bundle Nginx, ngx_http_lua, ngx_stream_lua, (this module), LuaJIT, as well as other powerful companion Nginx modules and Lua libraries.

It is discouraged to build this module with Nginx yourself since it is tricky to set up exactly right.

Note that Nginx, LuaJIT, and OpenSSL official releases have various limitations and long standing bugs that can cause some of this module's features to be disabled, not work properly, or run slower. Official OpenResty releases are recommended because they bundle OpenResty's optimized LuaJIT 2.1 fork and Nginx/OpenSSL patches.

Alternatively, ngx_stream_lua can be manually compiled into Nginx:

  1. LuaJIT can be downloaded from the latest release of OpenResty's LuaJIT fork. The official LuaJIT 2.x releases are also supported, although performance will be significantly lower for reasons elaborated above
  2. Download the latest version of ngx_stream_lua HERE
  3. Download the latest supported version of Nginx HERE (See Nginx Compatibility)

Build the source with this module:

wget 'https://nginx.org/download/nginx-1.13.6.tar.gz'
tar -xzvf nginx-1.13.6.tar.gz
cd nginx-1.13.6/

# tell nginx's build system where to find LuaJIT 2.1:
export LUAJIT_LIB=/path/to/luajit/lib
export LUAJIT_INC=/path/to/luajit/include/luajit-2.1

# Here we assume Nginx is to be installed under /opt/nginx/.
./configure --prefix=/opt/nginx \
        --with-ld-opt="-Wl,-rpath,/path/to/luajit-or-lua/lib" \
        --with-stream \
        --with-stream_ssl_module \
        --add-module=/path/to/stream-lua-nginx-module

# Build and install
make -j4
make install

You may use --without-http if you do not wish to use this module with the "http" subsystem. ngx_stream_lua will work perfectly fine without the "http" subsystem.

Back to TOC

Community

Back to TOC

English Mailing List

The openresty-en mailing list is for English speakers.

Back to TOC

Chinese Mailing List

The openresty mailing list is for Chinese speakers.

Back to TOC

Code Repository

The code repository of this project is hosted on GitHub at openresty/stream-lua-nginx-module.

Back to TOC

Bugs and Patches

Please submit bug reports, wishlists, or patches by

  1. creating a ticket on the GitHub Issue Tracker,
  2. or posting to the OpenResty community.

Back to TOC

Acknowledgments

We appreciate Kong Inc. for kindly sponsoring OpenResty Inc. on the following work:

  • Compatibility with Nginx core 1.13.3.
  • Development of meta-lua-nginx-module to make code sharing between this module and lua-nginx-module possible.
  • balancer_by_lua_*, preread_by_lua_*, log_by_lua_* and ssl_certby_lua* phases support.
  • reqsock:peek API support.

Back to TOC

Copyright and License

This module is licensed under the BSD license.

Copyright (C) 2009-2019, by Yichun "agentzh" Zhang (章亦春) [email protected], OpenResty Inc.

Copyright (C) 2009-2016, by Xiaozhe Wang (chaoslawful) [email protected].

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • 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.

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.

Back to TOC

See Also

Back to TOC

stream-lua-nginx-module's People

Contributors

agentzh avatar balusch avatar catbro666 avatar chipitsine avatar chronolaw avatar dndx avatar doujiang24 avatar fffonion avatar halfcrazy avatar hypebeast avatar itpp16 avatar lynch1981 avatar ngtee8 avatar omigafu avatar oowl avatar rainingmaster avatar spacewander avatar subnetmarco avatar swananan avatar tangsty avatar theweakgod avatar thibaultcha avatar vislee avatar willmafh avatar xiaocang avatar xuruidong avatar ytlm avatar zhongweiy avatar zhuizhuhaomeng avatar zjfans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stream-lua-nginx-module's Issues

关于使用lua table 共享ngx.req.socket的问题

是这样,我现在采用stream-lua 实现 mqtt broker的功能,在采用lua table 存储ngx.req.socket 的时候,在同一个worker进程间,不同的请求上下文中使用共享的socket调用send的方法的时候 出现如下异常

bad request
stack traceback:
coroutine 0:
[C]: in function 'send'

望大神解答 谢谢

The module could not use in new version of Openresty.

in openresty v.1.9.* can build and use stream and ngx_lua code.(use the v.0.0.1 stream-lua-nginx-module which u give the link to get this.)

in openresty v.1.11.* can not use stream ,when I test the nginx conf,it echo "段错误".(use v.0.0.1 or master).
image
image

followup on my pull

/src/ngx_stream_lua_util.c(1465) : error C2039: 'header_sent' : is not a member of 'ngx_stream_session_s'
src/stream\ngx_stream.h(139) : see declaration of 'ngx_stream_session_s'
/src/ngx_stream_lua_util.c(1727) : error C2065: 'ngx_stream_lua_ssl_cert_ctx_t' : undeclared identifier
/src/ngx_stream_lua_util.c(1727) : error C2065: 'cctx' : undeclared identifier
/src/ngx_stream_lua_util.c(1727) : warning C4552: '*' : operator has no effect; expected operator with side-effect
/src/ngx_stream_lua_util.c(1750) : error C2065: 'cctx' : undeclared identifier
/src/ngx_stream_lua_util.c(1750) : warning C4013: 'ngx_stream_lua_ssl_get_ctx' undefined; assuming extern returning int
/src/ngx_stream_lua_util.c(1751) : error C2065: 'cctx' : undeclared identifier
/src/ngx_stream_lua_util.c(1751) : warning C4047: '!=' : 'int' differs in levels of indirection from 'void *'
/src/ngx_stream_lua_util.c(1752) : error C2065: 'cctx' : undeclared identifier
/src/ngx_stream_lua_util.c(1752) : error C2223: left of '->exit_code' must point to struct/union
/src/ngx_stream_lua_util.c(2900) : error C2065: 'ngx_stream_cleanup_t' : undeclared identifier

/src/ngx_stream_lua_socket_tcp.c(1238) : error C2039: 'ssl' : is not a member of 'ngx_stream_lua_srv_conf_t'
\src\ngx_stream_lua_common.h(159) : see declaration of 'ngx_stream_lua_srv_conf_t'
/src/ngx_stream_lua_socket_tcp.c(1238) : warning C4133: 'function' : incompatible types - from 'ngx_connection_t *' to 'ngx_ssl_t *'
/src/ngx_stream_lua_socket_tcp.c(1239) : warning C4047: 'function' : 'ngx_connection_t *' differs in levels of indirection from 'int'
/src/ngx_stream_lua_socket_tcp.c(1239) : warning C4024: 'ngx_ssl_create_connection' : different types for formal and actual parameter 2
/src/ngx_stream_lua_socket_tcp.c(1239) : error C2198: 'ngx_ssl_create_connection' : too few arguments for call

/src/ngx_stream_lua_sleep.c(73) : error C2039: 'uri' : is not a member of 'ngx_stream_session_s'
src/stream\ngx_stream.h(139) : see declaration of 'ngx_stream_session_s'
/src/ngx_stream_lua_sleep.c(73) : error C2039: 'uri' : is not a member of 'ngx_stream_session_s'
src/stream\ngx_stream.h(139) : see declaration of 'ngx_stream_session_s'

Specific warnings not logged yet.

could be a bug

使用 openresty结合 stream_module 0.0.1版本,使用 mysql.lua和 redis.lua时,在协程切换的时候,出现 attempt to yield across metamethod/C-call boundary while handling client connection错误。use lua-5.1

how to close a ngx.req.socket(true)

I use this module to develop a tcp server, I need close the connection but the tcp created by ngx.req.socket cannot be closed. How can I do?

I user websocket before.Forgive me do not use websocket here.

can stream-lua-nginx-module load balance MQTT messages?

first, can stream-lua-nginx-module parse the MQTT message, and get the contents of the message. for example, got the version information from the message contents. second, according to the version information, it can load balance the MQTT message.

upstream or downstream

server {
listen 9003;
content_by_lua_block {
local tcpsock = ngx.req.socket(true)
while true do
local data, err = tcpsock:receive(5)
if not data then
ngx.say("failed to read data", err)
return
end
ngx.say("successfully read: ", data)
end
}
}

Above has no upstream defined. However, data is received from the client.
Is this expected ? Is upstream simply short-circuited to downstream in this case ?

My intention is to intercept and read upstream before proxy_pass directive takes effect.
Would that require the future TODO access_by_lua_block feature ?

UDP downstream api

Hi,

Would like to implement a udp proxy server (dns proxy) with stream and upstream modules.
Both send/receive messages are not longer than a single datagram.
I would also like to intercept response from upstream server (That is 'subrequest' in http module)

Would like to code/port missing parts to existing modules.
Any recommendations to where should I start ?

From what I have seen upstream-lua does not support udp and I'm not sure it's usable in the stream/server context and when considering porting then lua-nginx-module
does not support udp cosockets just yet

thanks

tcpsock:receive needs stream reading pattern

Now tcpsock:receive now support two pattern '_a' and '_l'(default '*l' if pattern is nil), it's quite useful in text-based protocol or open binary protocol(eg. Mysql).

But to deal with non-public protocol, we need stream reading pattern, return anything once socket receives.

For example, we hava a decode library(.so/.dll) privided by others who don't open their protocol, and we need to fill socket data into the library to decode message out. Without steam reading pattern, decode can't be done in efficient way (done by tcpsock:receive(1) loop).

I suggest to add stream reading pattern into tcpsock:receive, especially in stream-lua-nginx-module

Segmentation fault using lua_resolver

ngninx.conf

worker_rlimit_core 500M;
working_directory /tmp/cores/;
error_log stderr debug;
daemon off;

events {
    use epoll;
    multi_accept on;
}

http {
}

stream {
    lua_resolver 8.8.8.8;

    server {
        listen 9999 reuseport backlog=1024 ;

        content_by_lua_block {
            local sock, err = ngx.socket.tcp()
            if sock then
                local res, err = sock:connect("google.com", 80)
                if res then
                    ngx.say("ok")
                end
            end
            if err then ngx.say(err) end
        }
    }
}

error.log

2016/11/14 23:45:25 [debug] 518#518: bind() 0.0.0.0:9999 #4
2016/11/14 23:45:25 [notice] 518#518: using the "epoll" event method
2016/11/14 23:45:25 [debug] 518#518: counter: 00007F1EB42A0080, 1
2016/11/14 23:45:25 [notice] 518#518: openresty/1.9.15.1
2016/11/14 23:45:25 [notice] 518#518: built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
2016/11/14 23:45:25 [notice] 518#518: OS: Linux 4.4.27-moby
2016/11/14 23:45:25 [notice] 518#518: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2016/11/14 23:45:25 [debug] 518#518: write: 7, 00007FFCC9903430, 4, 0
2016/11/14 23:45:25 [debug] 518#518: setproctitle: "nginx: master process /usr/local/openresty/nginx/sbin/nginx -c /var/www/ring-socket-service/config/nginx.conf"
2016/11/14 23:45:25 [notice] 518#518: start worker processes
2016/11/14 23:45:25 [debug] 518#518: channel 3:7
2016/11/14 23:45:25 [notice] 518#518: start worker process 519
2016/11/14 23:45:25 [debug] 518#518: sigsuspend
2016/11/14 23:45:25 [debug] 519#519: notify eventfd: 9
2016/11/14 23:45:25 [debug] 519#519: eventfd: 10
2016/11/14 23:45:25 [debug] 519#519: malloc: 00007F1EB41C8DB0:6144
2016/11/14 23:45:25 [debug] 519#519: malloc: 00007F1EB41E0580:118784
2016/11/14 23:45:25 [debug] 519#519: malloc: 00007F1EB41FD590:49152
2016/11/14 23:45:25 [debug] 519#519: malloc: 00007F1EB42095A0:49152
2016/11/14 23:45:25 [debug] 519#519: epoll add event: fd:4 op:1 ev:00002001
2016/11/14 23:45:25 [debug] 519#519: REAPER: start reaper memstore message with tick time of 5 sec
2016/11/14 23:45:25 [debug] 519#519: REAPER: start reaper memstore nobuffer message with tick time of 2 sec
2016/11/14 23:45:25 [debug] 519#519: REAPER: start reaper chanhead with tick time of 4 sec
2016/11/14 23:45:25 [debug] 519#519: REAPER: start reaper chanhead churner with tick time of 10 sec
2016/11/14 23:45:25 [debug] 519#519: epoll add event: fd:5 op:1 ev:00002001
2016/11/14 23:45:25 [debug] 519#519: MEMSTORE:00: init memstore worker pid:519 slot:0 max workers :1 or 1
2016/11/14 23:45:25 [debug] 519#519: shmtx lock
2016/11/14 23:45:25 [debug] 519#519: MEMSTORE:00: found my procslot (ngx_process_slot 0, procslot 0)
2016/11/14 23:45:25 [debug] 519#519: MEMSTORE:00: shm: 00007F1EB41D4250, shdata: 00007F1EB0488000
2016/11/14 23:45:25 [debug] 519#519: shmtx unlock
2016/11/14 23:45:25 [debug] 519#519: WEBSOCKET_PUBLISHER:init WS publisher llist
2016/11/14 23:45:25 [debug] 519#519: malloc: 00007F1EB41BAB50:152
2016/11/14 23:45:25 [debug] 519#519: THINGCACHE: init fd_cache 00007F1EB41BAB50
2016/11/14 23:45:25 [debug] 519#519: epoll add event: fd:7 op:1 ev:00002001
2016/11/14 23:45:25 [debug] 519#519: setproctitle: "nginx: worker process"
2016/11/14 23:45:25 [debug] 519#519: worker cycle
2016/11/14 23:45:25 [debug] 519#519: epoll timer: -1
2016/11/14 23:45:27 [debug] 519#519: epoll: fd:4 ev:0001 d:00007F1EB41E0580
2016/11/14 23:45:27 [debug] 519#519: accept on 0.0.0.0:9999, ready: 1
2016/11/14 23:45:27 [debug] 519#519: posix_memalign: 00007F1EB41CA5C0:256 @16
2016/11/14 23:45:27 [debug] 519#519: *1 accept: 172.17.0.1:41198 fd:3
2016/11/14 23:45:27 [info] 519#519: *1 client 172.17.0.1:41198 connected to 0.0.0.0:9999
2016/11/14 23:45:27 [debug] 519#519: *1 tcp_nodelay
2016/11/14 23:45:27 [debug] 519#519: *1 posix_memalign: 00007F1EB41CA6D0:256 @16
2016/11/14 23:45:27 [debug] 519#519: *1 stream lua content handler fd:3
2016/11/14 23:45:27 [debug] 519#519: *1 malloc: 00007F1EB41CA7E0:368
2016/11/14 23:45:27 [debug] 519#519: *1 stream lua reset ctx
2016/11/14 23:45:27 [debug] 519#519: *1 stream lua creating new thread
2016/11/14 23:45:27 [debug] 519#519: *1 stream lua run thread, top:0
2016/11/14 23:45:27 [debug] 519#519: *1 stream lua tcp socket pool get keepalive peer
2016/11/14 23:45:27 [debug] 519#519: *1 stream lua tcp socket keepalive connection pool not found
2016/11/14 23:45:27 [debug] 519#519: *1 stream lua tcp socket connect timeout: 60000
2016/11/14 23:45:27 [debug] 519#519: malloc: 00007F1EB41CA960:224
2016/11/14 23:45:27 [debug] 519#519: resolve: "google.com"
2016/11/14 23:45:27 [debug] 519#519: malloc: 00007F1EB41CAA50:184
2016/11/14 23:45:27 [debug] 519#519: malloc: 00007F1EB41CAB10:10
2016/11/14 23:45:27 [debug] 519#519: malloc: 00007F1EB41CAB30:56
2016/11/14 23:45:27 [debug] 519#519: resolve: "google.com" A 15358
2016/11/14 23:45:27 [debug] 519#519: resolve: "google.com" AAAA 51876
2016/11/14 23:45:27 [debug] 519#519: UDP socket 11
2016/11/14 23:45:27 [debug] 519#519: connect to 8.8.8.8:53, fd:11 #2
2016/11/14 23:45:27 [debug] 519#519: epoll add event: fd:11 op:1 ev:80002001
2016/11/14 23:45:27 [debug] 519#519: send: fd:11 28 of 28
2016/11/14 23:45:27 [debug] 519#519: send: fd:11 28 of 28
2016/11/14 23:45:27 [debug] 519#519: malloc: 00007F1EB41BABF0:96
2016/11/14 23:45:27 [debug] 519#519: event timer add: -1: 30000:1479167157512
2016/11/14 23:45:27 [debug] 519#519: event timer add: -1: 5000:1479167132512
2016/11/14 23:45:27 [debug] 519#519: *1 stream lua resume returned 1
2016/11/14 23:45:27 [debug] 519#519: *1 stream lua thread yielded
2016/11/14 23:45:27 [debug] 519#519: *1 stream lua finalize: rc=-4
2016/11/14 23:45:27 [debug] 519#519: accept() not ready (11: Resource temporarily unavailable)
2016/11/14 23:45:27 [debug] 519#519: timer delta: 2215
2016/11/14 23:45:27 [debug] 519#519: worker cycle
2016/11/14 23:45:27 [debug] 519#519: epoll timer: 5000
2016/11/14 23:45:27 [debug] 519#519: epoll: fd:11 ev:0001 d:00007F1EB41E0920
2016/11/14 23:45:27 [debug] 519#519: recv: fd:11 56 of 4096
2016/11/14 23:45:27 [debug] 519#519: resolver DNS response 51876 fl:8180 1/1/0/0
2016/11/14 23:45:27 [debug] 519#519: resolver DNS response qt:28 cl:1
2016/11/14 23:45:27 [debug] 519#519: malloc: 00007F1EB41CAB70:10
2016/11/14 23:45:27 [debug] 519#519: resolver qs:google.com
2016/11/14 23:45:27 [debug] 519#519: resolver naddrs:1 cname:0000000000000000 ttl:175
2016/11/14 23:45:27 [debug] 519#519: recv: fd:11 124 of 4096
2016/11/14 23:45:27 [debug] 519#519: resolver DNS response 15358 fl:8180 1/6/0/0
2016/11/14 23:45:27 [debug] 519#519: resolver DNS response qt:1 cl:1
2016/11/14 23:45:27 [debug] 519#519: malloc: 00007F1EB41CAB70:10
2016/11/14 23:45:27 [debug] 519#519: resolver qs:google.com
2016/11/14 23:45:27 [debug] 519#519: resolver naddrs:6 cname:0000000000000000 ttl:175
2016/11/14 23:45:27 [debug] 519#519: malloc: 00007F1EB41CAB70:24
2016/11/14 23:45:27 [debug] 519#519: malloc: 00007F1EB41CAB90:280
2016/11/14 23:45:27 [debug] 519#519: malloc: 00007F1EB41CACB0:770
2016/11/14 23:45:27 [debug] 519#519: *1 stream lua tcp socket resolve handler
2016/11/14 23:45:27 [debug] 519#519: *1 name was resolved to 64.233.186.139
2016/11/14 23:45:27 [notice] 518#518: signal 17 (SIGCHLD) received
2016/11/14 23:45:27 [alert] 518#518: worker process 519 exited on signal 11 (core dumped)
2016/11/14 23:45:27 [debug] 518#518: shmtx forced unlock
2016/11/14 23:45:27 [debug] 518#518: shmtx forced unlock
2016/11/14 23:45:27 [debug] 518#518: wake up, sigio 0
2016/11/14 23:45:27 [debug] 518#518: reap children
2016/11/14 23:45:27 [debug] 518#518: child: 0 519 e:0 t:1 d:0 r:1 j:0
2016/11/14 23:45:27 [debug] 518#518: channel 3:7
2016/11/14 23:45:27 [notice] 518#518: start worker process 520
2016/11/14 23:45:27 [debug] 518#518: sigsuspend
2016/11/14 23:45:27 [debug] 520#520: notify eventfd: 9
2016/11/14 23:45:27 [debug] 520#520: eventfd: 10
2016/11/14 23:45:27 [debug] 520#520: malloc: 00007F1EB41C8DB0:6144
2016/11/14 23:45:27 [debug] 520#520: malloc: 00007F1EB41E0580:118784
2016/11/14 23:45:27 [debug] 520#520: malloc: 00007F1EB41FD590:49152
2016/11/14 23:45:27 [debug] 520#520: malloc: 00007F1EB42095A0:49152
2016/11/14 23:45:27 [debug] 520#520: epoll add event: fd:4 op:1 ev:00002001
2016/11/14 23:45:27 [debug] 520#520: REAPER: start reaper memstore message with tick time of 5 sec
2016/11/14 23:45:27 [debug] 520#520: REAPER: start reaper memstore nobuffer message with tick time of 2 sec
2016/11/14 23:45:27 [debug] 520#520: REAPER: start reaper chanhead with tick time of 4 sec
2016/11/14 23:45:27 [debug] 520#520: REAPER: start reaper chanhead churner with tick time of 10 sec
2016/11/14 23:45:27 [debug] 520#520: epoll add event: fd:5 op:1 ev:00002001
2016/11/14 23:45:27 [debug] 520#520: MEMSTORE:00: init memstore worker pid:520 slot:0 max workers :1 or 1
2016/11/14 23:45:27 [debug] 520#520: shmtx lock
2016/11/14 23:45:27 [debug] 520#520: MEMSTORE:00: found my procslot (ngx_process_slot 0, procslot 0)
2016/11/14 23:45:27 [debug] 520#520: MEMSTORE:00: shm: 00007F1EB41D4250, shdata: 00007F1EB0488000
2016/11/14 23:45:27 [debug] 520#520: shmtx unlock
2016/11/14 23:45:27 [debug] 520#520: WEBSOCKET_PUBLISHER:init WS publisher llist
2016/11/14 23:45:27 [debug] 520#520: malloc: 00007F1EB41BAB50:152
2016/11/14 23:45:27 [debug] 520#520: THINGCACHE: init fd_cache 00007F1EB41BAB50
2016/11/14 23:45:27 [debug] 520#520: epoll add event: fd:7 op:1 ev:00002001
2016/11/14 23:45:27 [debug] 520#520: setproctitle: "nginx: worker process"
2016/11/14 23:45:27 [debug] 520#520: worker cycle
2016/11/14 23:45:27 [debug] 520#520: epoll timer: -1

Core dump

Program terminated with signal SIGSEGV, Segmentation fault.
#0  ngx_sock_ntop (sa=0x0, socklen=3021778206, text=text@entry=0x7ffcc9901ff0 "64.233.186.139", len=len@entry=113, port=port@entry=0) at src/core/ngx_inet.c:194
194 src/core/ngx_inet.c: No such file or directory.
(gdb) backtrace
#0  ngx_sock_ntop (sa=0x0, socklen=3021778206, text=text@entry=0x7ffcc9901ff0 "64.233.186.139", len=len@entry=113, port=port@entry=0) at src/core/ngx_inet.c:194
#1  0x00000000005aa706 in ngx_stream_lua_socket_resolve_handler (ctx=0x7f1eb41ca960) at /tmp/stream-lua-nginx-module-0.0.1/src/ngx_stream_lua_socket_tcp.c:835
#2  0x000000000047321b in ngx_resolver_process_a (ans=<optimized out>, trunc=<optimized out>, nan=<optimized out>, qtype=<optimized out>, code=<optimized out>,
    ident=<optimized out>, n=<optimized out>, buf=0x7ffcc99020b0 "\257", r=<optimized out>) at src/core/ngx_resolver.c:2431
#3  ngx_resolver_process_response (r=<optimized out>, buf=buf@entry=0x7ffcc9902190 ";\376\201\200", n=<optimized out>, tcp=tcp@entry=0) at src/core/ngx_resolver.c:1835
#4  0x00000000004745b5 in ngx_resolver_udp_read (rev=0x7f1eb41fd710) at src/core/ngx_resolver.c:1576
#5  0x0000000000482699 in ngx_epoll_process_events (cycle=0x7f1eb41bbdc0, timer=<optimized out>, flags=<optimized out>) at src/event/modules/ngx_epoll_module.c:822
#6  0x00000000004786d7 in ngx_process_events_and_timers (cycle=cycle@entry=0x7f1eb41bbdc0) at src/event/ngx_event.c:242
#7  0x0000000000480035 in ngx_worker_process_cycle (cycle=cycle@entry=0x7f1eb41bbdc0, data=data@entry=0x0) at src/os/unix/ngx_process_cycle.c:753
#8  0x000000000047eb00 in ngx_spawn_process (cycle=cycle@entry=0x7f1eb41bbdc0, proc=proc@entry=0x47fff0 <ngx_worker_process_cycle>, data=data@entry=0x0,
    name=name@entry=0x786660 "worker process", respawn=respawn@entry=-3) at src/os/unix/ngx_process.c:198
#9  0x00000000004802a4 in ngx_start_worker_processes (cycle=cycle@entry=0x7f1eb41bbdc0, n=1, type=type@entry=-3) at src/os/unix/ngx_process_cycle.c:358
#10 0x0000000000480fdf in ngx_master_process_cycle (cycle=cycle@entry=0x7f1eb41bbdc0) at src/os/unix/ngx_process_cycle.c:130
#11 0x0000000000459d39 in main (argc=<optimized out>, argv=<optimized out>) at src/core/nginx.c:367

nginx -V

nginx version: openresty/1.9.15.1
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
built with OpenSSL 1.0.2j  26 Sep 2016
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-debug --with-cc-opt='-DNGX_LUA_USE_ASSERT -DNGX_LUA_ABORT_AT_PANIC -O2' --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.59 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.30 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.05 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.5 --add-module=../ngx_lua_upstream-0.05 --add-module=../headers-more-nginx-module-0.30 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.17 --add-module=../redis2-nginx-module-0.13 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-openssl=/tmp/openssl-1.0.2j --with-pcre=/tmp/pcre-8.39 --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-ipv6 --with-mail --with-mail_ssl_module --with-md5-asm --with-pcre-jit --with-sha1-asm --with-stream --with-stream_ssl_module --with-threads --add-module=/tmp/nchan-0.99.16 --add-module=/tmp/stream-lua-nginx-module-0.0.1

Nginx crash because ngx_stream_lua_finalize_session was called more than once

Nginx config file like bellow. It's the same as TSET12 in t/106-timer.t

worker_processes  1;
daemon off;
master_process off;
events {
    use epoll;
}
stream {
    server {
        listen 1988;
        content_by_lua_block {
            local function fail (...)
                ngx.log(ngx.ERR, ...)
            end
            local function handle()
                function f()
                    print("hello in thread")
                    return "done"
                end

                local t, err = ngx.thread.spawn(f)
                if not t then
                    fail("failed to spawn thread: ", err)
                    return
                end

                print("thread created: ", coroutine.status(t))

   
                collectgarbage()

                local ok, res = ngx.thread.wait(t)
                if not ok then
                    fail("failed to run thread: ", res)
                    return
                end

                print("wait result: ", res)
            end
            
            local ok, err = ngx.timer.at(0.01, handle)
            if not ok then
                ngx.say("failed to set timer: ", err)
                return
            end
            ngx.say("registered timer")
        }
    }
}

Nginx receive segment fault when process request.

gdb debuginfo like this


Breakpoint 1, ngx_stream_lua_finalize_session (s=0x7ffff7efb1f0, rc=0) at /home/kenan/Git/stream-lua-nginx-module/src/ngx_stream_lua_util.c:596
596	    ctx = ngx_stream_get_module_ctx(s, ngx_stream_lua_module);
(gdb) bt
#0  ngx_stream_lua_finalize_session (s=0x7ffff7efb1f0, rc=0) at /home/kenan/Git/stream-lua-nginx-module/src/ngx_stream_lua_util.c:596
#1  0x00000000005a70a7 in ngx_stream_lua_run_posted_threads (c=0x7ffff7f09278, L=0x40000378, s=0x7ffff7efb1f0, ctx=0x7ffff7ef4d30) at /home/kenan/Git/stream-lua-nginx-module/src/ngx_stream_lua_util.c:1732
#2  0x00000000005ceb6a in ngx_stream_lua_timer_handler (ev=0x0) at /home/kenan/Git/stream-lua-nginx-module/src/ngx_stream_lua_timer.c:490
#3  0x0000000000455fa0 in ngx_event_expire_timers () at src/event/ngx_event_timer.c:94
#4  0x000000000045393b in ngx_process_events_and_timers (cycle=0x7ffff7ef59c0) at src/event/ngx_event.c:256
#5  0x00000000004618a8 in ngx_single_process_cycle (cycle=0x7ffff7ef59c0) at src/os/unix/ngx_process_cycle.c:309
#6  0x000000000041cfa0 in main (argc=3, argv=0x7fffffffe4f8) at src/core/nginx.c:364
(gdb) c
Continuing.

Breakpoint 1, ngx_stream_lua_finalize_session (s=0x7ffff7efb1f0, rc=-4) at /home/kenan/Git/stream-lua-nginx-module/src/ngx_stream_lua_util.c:596
596	    ctx = ngx_stream_get_module_ctx(s, ngx_stream_lua_module);
(gdb) bt
#0  ngx_stream_lua_finalize_session (s=0x7ffff7efb1f0, rc=-4) at /home/kenan/Git/stream-lua-nginx-module/src/ngx_stream_lua_util.c:596
#1  0x00000000005ceb97 in ngx_stream_lua_timer_handler (ev=0x0) at /home/kenan/Git/stream-lua-nginx-module/src/ngx_stream_lua_timer.c:496
#2  0x0000000000455fa0 in ngx_event_expire_timers () at src/event/ngx_event_timer.c:94
#3  0x000000000045393b in ngx_process_events_and_timers (cycle=0x7ffff7ef59c0) at src/event/ngx_event.c:256
#4  0x00000000004618a8 in ngx_single_process_cycle (cycle=0x7ffff7ef59c0) at src/os/unix/ngx_process_cycle.c:309
#5  0x000000000041cfa0 in main (argc=3, argv=0x7fffffffe4f8) at src/core/nginx.c:364
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x00000000005a5084 in ngx_stream_lua_finalize_session (s=0x7ffff7efb1f0, rc=-4) at /home/kenan/Git/stream-lua-nginx-module/src/ngx_stream_lua_util.c:597
597	    if (ctx && ctx->cur_co_ctx) {
(gdb) 

The function ngx_stream_finalize_session was called twice. Unlike the HTTP module, ngx_stream_session_t has not member as a reference count(like r->count), so ngx_stream_lua_finalize_session must be called only once.

Closing connections to peers

I'm starting a timer in init_worker_by_lua_block() and checking upstream peer health via http.
If a peer is not healthy, I set its 'down' flag to 1. Which routes new connections to other peers. However, old connections are not closed and clients keep using the non-healthy peers.

Could you please point me to any examples on how I can close existing connections to one of the peers from the timer handler?

Can't compile additional modules

Can't compile my module https://github.com/ZigzagAK/lua-stream-upstream-nginx-module (support lua api for stream).

Output:

  1. trouble №1
    cc1: warnings being treated as errors
    stream-lua-nginx-module/src/ngx_stream_lua_util.c: В функции ‘ngx_stream_lua_free_session’:
    stream-lua-nginx-module/src/ngx_stream_lua_util.c:3206: ошибка: неявная декларация функции ‘ngx_stream_close_connection’

  2. trouble №2 on compilation my module because there are no implementation has been found in stream-lua-nginx-module.
    objs/addon/src/ngx_stream_lua_upstream_module.o: In function ngx_stream_lua_upstream_init': /home/aleksey/nginx/nginx-1.11.5-src/lua-stream-upstream-nginx-module/src/ngx_stream_lua_upstream_module.c:63: undefined reference to ngx_stream_lua_add_package_preload'
    objs/addon/src/ngx_stream_lua_upstream_module.o: In function ngx_stream_lua_upstream_get_upstream_main_conf': /home/aleksey/nginx/nginx-1.11.5-src/lua-stream-upstream-nginx-module/src/ngx_stream_lua_upstream_module.c:487: undefined reference to ngx_stream_lua_get_session'
    objs/addon/src/ngx_stream_lua_upstream_module.o: In function ngx_stream_lua_upstream_current_upstream_name': /home/aleksey/nginx/nginx-1.11.5-src/lua-stream-upstream-nginx-module/src/ngx_stream_lua_upstream_module.c:557: undefined reference to ngx_stream_lua_get_session'

Reason:
2 patches:
1. nginx.patch
nginx.patch.gz

2. stream-lua-nginx-module.patch

stream-lua-nginx-module.patch.gz

cppcheck finding

[src/ngx_stream_lua_clfactory.c:621] -> [src/ngx_stream_lua_clfactory.c:642]: (warning) Either the condition 'c==LUA_SIGNATURE[0]&&filename' is redundant or there is possible null pointer dereference: filename.

Compile it with high version nginx, like nginx 1.9

You must attention:

  1. --with-stream must not be dynamic, --with-stream=dynaimc is wrong
  2. openssl must be v1.0.2, this project do not support 1.1.0. Of course, you must make && make install openssl first
  3. --with-http_perl_module is conflict with this project, remove this line in configure command
  4. LD,CC's options like this
--with-cc-opt='-O2 -I/usr/include -I/usr/include/openssl' \
--with-ld-opt='-Wl,-rpath,/usr/lib' \
  1. if your nginx's version > 1.10
    replace ngx_stream_close_connection(s->connection); to ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); in file stream-lua-nginx-module/src/ngx_stream_lua_util.c
  2. replace your nginx's file auto/lib/openssl/conf
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"

to

CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/libcrypto.a"

so the complete configure commad like this:

./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/lib/nginx/tmp/client_body \
--http-proxy-temp-path=/var/lib/nginx/tmp/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi \
--http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi \
--http-scgi-temp-path=/var/lib/nginx/tmp/scgi \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/subsys/nginx \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_auth_request_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-pcre \
--with-pcre-jit \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-debug \
--with-cc-opt='-O2 -I/usr/include -I/usr/include/openssl' \
--with-ld-opt='-Wl,-rpath,/usr/lib' \
--with-openssl=~/openssl-1.0.2l \
--add-module=../ngx_devel_kit \
--add-module=../echo-nginx-module \
--add-module=../xss-nginx-module \
--add-module=../ngx_coolkit \
--add-module=../set-misc-nginx-module \
--add-module=../memc-nginx-module \
--add-module=../form-input-nginx-module \
--add-module=../encrypted-session-nginx-module \
--add-module=../headers-more-nginx-module \
--add-module=../array-var-nginx-module \
--add-module=../redis2-nginx-module \
--add-module=../srcache-nginx-module \
--add-module=../lua-nginx-module \
--add-module=../lua-upstream-nginx-module \
--add-module=../stream-lua-nginx-module

Is HTTP or Stream

When in phases with the same name it is often necessary to know if the phase is executing in the http module system or the stream modules system.

Perhaps a variable or a method like get_phase (get_system?)?

Able to rewrite proxy_pass server?

Hello,

I'm attempting to dynamically route tcp traffic with Lua. Is this possible with this module? I want to have Lua grab a value from redis and set this as the backend per request.

objs/addon/src/ngx_stream_lua_socket_tcp.o

Nginx version:
nginx-1.10.3
error log:

../stream-lua-nginx-module-0.0.1/src/ngx_stream_lua_socket_tcp.c:819:15: error: assignment from incompatible pointer type [-Werror]
     ur->addrs = ctx->addrs;
               ^
cc1: all warnings being treated as errors
make[1]: *** [objs/addon/src/ngx_stream_lua_socket_tcp.o] Error 1

Can I compile the module as dynamic

Hello, I have tried to compile the module with the --add-dynamic-module flag in the configure script but I don't find any .so file, so my understanding is that I need to modify the config file, or maybe it is not possible at all to have it as dynamic.

Thanks

Dynamic TLS/SNI hostname routing/balancing with LUA and Redis

First - great work with LUA support in Nginx. Based on this idea we build dynamic router based on host name. Works like a charm. But this is for HTTP traffic only. How can we extend it to TLS streams?

Idea is simple: route incoming TLS connection to backend servers based on SNI hostname. The problem is how to map many-to-many TLS connection dynamical (no nginx restart/reload, just by adding Redis entry)?

Most of the work is done. Nginx can perform SNI preread, we have LUA support for 'stream'. What is missing how to provide 'proxy_pass' from LUA variable (fetch from Redis based on Nginx $ssl_preread_server_name? Simple: do this mapping with Redis.

Make sens?

Chris

ngx.req.udp_socket is not work, why?

error: lua entry thread aborted: runtime error: content_by_lua(nginx.conf:25):4: attempt to call field 'udp_socket' (a nil value)

nginx.conf :

stream{
        server{
                listen 81 udp;
                content_by_lua_block {
                        local sock = ngx.req.udp_socket()
                        sock:send("Ok\n\n")
                }
        }
}

Compile this module error

I have downloaded openresty-1.9.7.3 and stream-lua-nginx-module@master branch in my Ubuntu 14.04. And I typed ./configure --prefix=./nginx --with-stream --with-stream_ssl_module --add-module=../stream-lua-nginx-module-master, there is nothing happened. Then typed "make", there is one errors happened. The errors look like this:

<command-line>:0:19: error: 'lualib' undeclared (first use in this function)
/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1/lua.
h:275:24: note: in definition of macro 'lua_pushliteral'
  lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
                        ^
../ngx_lua-0.10.0/src/ngx_http_lua_util.c:240:28: note: in expansion of macro 'LUA_DEFAULT_PATH'
         lua_pushliteral(L, LUA_DEFAULT_PATH ";"); /* package default */
                            ^
<command-line>:0:19: note: each undeclared identifier is reported only once for each function it appears
 in
/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1/lua.
h:275:24: note: in definition of macro 'lua_pushliteral'
  lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
                        ^
../ngx_lua-0.10.0/src/ngx_http_lua_util.c:240:28: note: in expansion of macro 'LUA_DEFAULT_PATH'
         lua_pushliteral(L, LUA_DEFAULT_PATH ";"); /* package default */
                            ^
<command-line>:0:26: error: expected expression before '?' token
/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1/lua.
h:275:24: note: in definition of macro 'lua_pushliteral'
  lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
                        ^
../ngx_lua-0.10.0/src/ngx_http_lua_util.c:240:28: note: in expansion of macro 'LUA_DEFAULT_PATH'
         lua_pushliteral(L, LUA_DEFAULT_PATH ";"); /* package default */
                            ^
<command-line>:0:26: error: missing terminating " character
/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1/lua.
h:275:24: note: in definition of macro 'lua_pushliteral'
  lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
                        ^
../ngx_lua-0.10.0/src/ngx_http_lua_util.c:240:28: note: in expansion of macro 'LUA_DEFAULT_PATH'
         lua_pushliteral(L, LUA_DEFAULT_PATH ";"); /* package default */
                            ^
<command-line>:0:26: error: missing terminating " character
/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1/lua.
h:275:24: note: in definition of macro 'lua_pushliteral'
  lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
                        ^
../ngx_lua-0.10.0/src/ngx_http_lua_util.c:240:28: note: in expansion of macro 'LUA_DEFAULT_PATH'
         lua_pushliteral(L, LUA_DEFAULT_PATH ";"); /* package default */
                            ^
<command-line>:0:26: error: too few arguments to function 'lua_pushlstring'
/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1/lua.
h:275:24: note: in definition of macro 'lua_pushliteral'
  lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
                        ^
../ngx_lua-0.10.0/src/ngx_http_lua_util.c:240:28: note: in expansion of macro 'LUA_DEFAULT_PATH'
         lua_pushliteral(L, LUA_DEFAULT_PATH ";"); /* package default */
                            ^
/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1/lua.
h:163:16: note: declared here
 LUA_API void  (lua_pushlstring) (lua_State *L, const char *s, size_t l);
                ^
<command-line>:0:27: error: expected expression before '?' token
/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1/lua.
h:275:24: note: in definition of macro 'lua_pushliteral'
  lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
                        ^
../ngx_lua-0.10.0/src/ngx_http_lua_util.c:253:28: note: in expansion of macro 'LUA_DEFAULT_CPATH'
         lua_pushliteral(L, LUA_DEFAULT_CPATH ";"); /* package default */
                            ^
<command-line>:0:27: error: missing terminating " character
/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1/lua.
h:275:24: note: in definition of macro 'lua_pushliteral'
  lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
                        ^
../ngx_lua-0.10.0/src/ngx_http_lua_util.c:253:28: note: in expansion of macro 'LUA_DEFAULT_CPATH'
         lua_pushliteral(L, LUA_DEFAULT_CPATH ";"); /* package default */
                            ^
<command-line>:0:27: error: missing terminating " character
/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1/lua.
h:275:24: note: in definition of macro 'lua_pushliteral'
  lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
                        ^
../ngx_lua-0.10.0/src/ngx_http_lua_util.c:253:28: note: in expansion of macro 'LUA_DEFAULT_CPATH'
         lua_pushliteral(L, LUA_DEFAULT_CPATH ";"); /* package default */
                            ^
<command-line>:0:27: error: too few arguments to function 'lua_pushlstring'
/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1/lua.
h:275:24: note: in definition of macro 'lua_pushliteral'
  lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
                        ^
../ngx_lua-0.10.0/src/ngx_http_lua_util.c:253:28: note: in expansion of macro 'LUA_DEFAULT_CPATH'
         lua_pushliteral(L, LUA_DEFAULT_CPATH ";"); /* package default */
                            ^
/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1/lua.
h:163:16: note: declared here
 LUA_API void  (lua_pushlstring) (lua_State *L, const char *s, size_t l);
                ^
cc -c -I/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-
2.1 -I/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.
1  -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -g -O2 -DNDK_SET_VAR -DNDK_UPSTREAM_LIST -DN
DK_SET_VAR -DNDK_SET_VAR -DNDK_SET_VAR -DLUA_DEFAULT_PATH='/lualib/?.lua;nginx/lualib/?/init.lua"' -DLUA
_DEFAULT_CPATH='/lualib/?.so"' -DNDK_SET_VAR  -I src/core -I src/event -I src/event/modules -I src/http 
-I src/http/modules -I src/os/unix -I ../ngx_devel_kit-0.2.19/objs -I objs/addon/ndk -I /home/htoooth/op
enresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1 -I ../ngx_lua-0.10.0
/src/api -I /home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/lua
jit-2.1 -I /home/htoooth/openresty_bundler/openresty-1.9.7.3/../stream-lua-nginx-module-master/src/api -
I objs -I src/http -I src/http/modules -I ../ngx_devel_kit-0.2.19/src -I src/mail -I src/stream \
                -o objs/addon/src/ngx_http_lua_setby.o \
                ../ngx_lua-0.10.0/src/ngx_http_lua_setby.c
cc -c -I/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-
2.1 -I/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.
1  -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -g -O2 -DNDK_SET_VAR -DNDK_UPSTREAM_LIST -DN
DK_SET_VAR -DNDK_SET_VAR -DNDK_SET_VAR -DLUA_DEFAULT_PATH='/lualib/?.lua;nginx/lualib/?/init.lua"' -DLUA
_DEFAULT_CPATH='/lualib/?.so"' -DNDK_SET_VAR  -I src/core -I src/event -I src/event/modules -I src/http 
-I src/http/modules -I src/os/unix -I ../ngx_devel_kit-0.2.19/objs -I objs/addon/ndk -I /home/htoooth/op
enresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1 -I ../ngx_lua-0.10.0
/src/api -I /home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/lua
jit-2.1 -I /home/htoooth/openresty_bundler/openresty-1.9.7.3/../stream-lua-nginx-module-master/src/api -
I objs -I src/http -I src/http/modules -I ../ngx_devel_kit-0.2.19/src -I src/mail -I src/stream \
                -o objs/addon/src/ngx_http_lua_capturefilter.o \
                ../ngx_lua-0.10.0/src/ngx_http_lua_capturefilter.c
<command-line>:0:55: warning: missing terminating " character [enabled by default]
<command-line>:0:31: warning: missing terminating " character [enabled by default]
<command-line>:0:55: warning: missing terminating " character [enabled by default]
<command-line>:0:31: warning: missing terminating " character [enabled by default]
_VAR -DLUA_DEFAULT_PATH='/lualib/?.lua;nginx/lualib/?/init.lua"' -DLUA_DEFAULT_CPATH='/lualib/?.so"' -DNDK_SET_VAR  -I src/core -I src/event -I src/event/modules -I src/http
 -I src/http/modules -I src/os/unix -I ../ngx_devel_kit-0.2.19/objs -I objs/addon/ndk -I /home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/inc
lude/luajit-2.1 -I ../ngx_lua-0.10.0/src/api -I /home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1 -I /home/htoooth/openrest
y_bundler/openresty-1.9.7.3/../stream-lua-nginx-module-master/src/api -I objs -I src/http -I src/http/modules -I ../ngx_devel_kit-0.2.19/src -I src/mail -I src/stream \
                -o objs/addon/src/ngx_http_lua_setby.o \
                ../ngx_lua-0.10.0/src/ngx_http_lua_setby.c
cc -c -I/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1 -I/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-
root/nginx/luajit/include/luajit-2.1  -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -g -O2 -DNDK_SET_VAR -DNDK_UPSTREAM_LIST -DNDK_SET_VAR -DNDK_SET_VAR -DNDK_SET
_VAR -DLUA_DEFAULT_PATH='/lualib/?.lua;nginx/lualib/?/init.lua"' -DLUA_DEFAULT_CPATH='/lualib/?.so"' -DNDK_SET_VAR  -I src/core -I src/event -I src/event/modules -I src/http
 -I src/http/modules -I src/os/unix -I ../ngx_devel_kit-0.2.19/objs -I objs/addon/ndk -I /home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/inc
lude/luajit-2.1 -I ../ngx_lua-0.10.0/src/api -I /home/htoooth/openresty_bundler/openresty-1.9.7.3/build/luajit-root/nginx/luajit/include/luajit-2.1 -I /home/htoooth/openrest
y_bundler/openresty-1.9.7.3/../stream-lua-nginx-module-master/src/api -I objs -I src/http -I src/http/modules -I ../ngx_devel_kit-0.2.19/src -I src/mail -I src/stream \
                -o objs/addon/src/ngx_http_lua_capturefilter.o \
                ../ngx_lua-0.10.0/src/ngx_http_lua_capturefilter.c
<command-line>:0:55: warning: missing terminating " character [enabled by default]
<command-line>:0:31: warning: missing terminating " character [enabled by default]
<command-line>:0:55: warning: missing terminating " character [enabled by default]
<command-line>:0:31: warning: missing terminating " character [enabled by default]
make[2]: *** [objs/addon/src/ngx_http_lua_util.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory `/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/nginx-1.9.7'
make[1]: *** [build] Error 2
make[1]: Leaving directory `/home/htoooth/openresty_bundler/openresty-1.9.7.3/build/nginx-1.9.7'
make: *** [all] Error 2

I don't know what's wrong with this module.

Broken pipe

I want to make a redis proxy. when I start my demo service with ip:port, the demo service works,

shell> redis-cli -h 10.171.233.97 -p 1234
redis 10.171.233.97:1234> foo
OK
redis 10.171.233.97:1234> bar
OK

but when i start it with unix domain socket, it only work at first time request, it will exit at second time request.

shell> redis-cli -s /tmp/redis.sock
redis /tmp/redis.sock> foo
OK
redis /tmp/redis.sock> bar
[exit]

I test my demo service through redis-cli, I strace it, when it exit, I find error msg (Broken pipe)

nginx.conf & test.lua: https://gist.github.com/wbcb/a4be7693d9f1cb395c9ad5de8ad1edb7

Contexts

Do you have plans to introduce other contexts such as something similar to access or rewrite (start of TCP stream). Or filter contexts such as body filtering?

With filtering, the cost of marshalling between lua strings and the char*'s representing the payload should probably be considered as many streams could be considerably large. FFI?

Oh and thank you for this release, I have a few ideas for things to try with this.

cppcheck issues

[src/ngx_stream_lua_regex.c:444] -> [src/ngx_stream_lua_regex.c:465]: (warning) Possible null pointer dereference: lmcf - otherwise it is redundant to check it against null.

[src/ngx_stream_lua_regex.c:903] -> [src/ngx_stream_lua_regex.c:924]: (warning) Possible null pointer dereference: lmcf - otherwise it is redundant to check it against null.

[src/ngx_stream_lua_regex.c:1644] -> [src/ngx_stream_lua_regex.c:1665]: (warning) Possible null pointer dereference: lmcf - otherwise it is redundant to check it against null.

shared dict feature

globally shared dict instance - accesable from both http and stream contexts

Broken compilation against NginX-1.11.4

.../nginx-1.11.4/work/stream-lua-nginx-module-aafd50b2e03fb36a88c2aff81d883d985dcc517f/src/ngx_stream_lua_util.c: In function 'ngx_stream_lua_free_session':
.../nginx-1.11.4/work/stream-lua-nginx-module-aafd50b2e03fb36a88c2aff81d883d985dcc517f/src/ngx_stream_lua_util.c:3206:9: warning: implicit declaration of function 'ngx_stream_close_connection' [-Wimplicit-function-declaration]
         ngx_stream_close_connection(s->connection);
         ^
configuring for Linux 4.7.2 x86_64
checking for C compiler: x86_64-pc-linux-gnu-gcc
 + using GNU C compiler
 + gcc version 5.4.0 (Gentoo 5.4.0 p1.0, pie-0.6.5)
<...>
 + PCRE version: 8.39
cp nginx.pm blib/lib/nginx.pm
Running Mkbootstrap for nginx ()
Manifying 1 pod document
objs/addon/src/ngx_stream_lua_util.o: In function `ngx_stream_lua_free_session':
ngx_stream_lua_util.c:(.text+0x28fc): undefined reference to `ngx_stream_close_connection'
ngx_stream_lua_util.c:(.text+0x2905): undefined reference to `ngx_stream_close_connection'
collect2: error: ld returned 1 exit status
make[1]: *** [objs/Makefile:676: objs/nginx] Error 1
make: *** [Makefile:8: build] Error 2

[bug] connection won't be closed when using ngx.thread.spawn

Example: test.lua

local function say_hello()
    return ngx.say("hello")
end

for i = 1, 3 do

    ngx.sleep(1.0)
    local co = ngx.thread.spawn(say_hello)
    ngx.thread.wait(co)

end

-- the clinet connection will not be close
-- it's a bug, but we can workaround with ngx.sleep
--ngx.sleep(0.001)

After printing three "hello", the client's connection won't be closed after the "world" exit.
It's a bug, but we can workaround with ngx.sleep.

I run this code under stream-lua-nginx-module and listen port 1234, here is the result

nc 127.0.0.1 1234
hello
hello
hello
-- wait here forever, the connection won't be closed.

if uncomment code "ngx.sleep(0.001)", the connection will be closed correctly.

nc 127.0.0.1 1234
hello
hello
hello
-- connection closed.

unknown directive "stream" with latest OpenResty

Hi, Im new to openresty, I was trying to get a http server listening on port 80 and a tcp server listening on port 12341.
I have compiled openresty (openresty-1.11.2.2) with build option mentioned below:
./configure -j2 --with-pcre-jit
--with-ipv6
--with-threads
--with-luajit
--with-ld-opt="-Wl,-rpath,/usr/local/openresty/luajit/lib/"
--with-stream
--add-module=$PWD/bundle/stream-lua-nginx-module-0.0.1

While testing the nginx.conf I am getting this error
$: sudo nginx -t -c pwd/nginx.conf
nginx: [emerg] unknown directive "stream" in /usr/local/openresty/nginx/conf/nginx.conf:20
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test failed

nginx.confg:
_user www-data;
worker_processes auto;
pid /run/openresty.pid;
events {
worker_connections 1024;
}
stream {
# define a TCP server listening on the port 1234:
server {
listen 12341;

    content_by_lua_block {
        ngx.say("Hello, Lua!")
    }
}

}

http {
include mime.types;
default_type application/octet-stream;

sendfile        on;
tcp_nopush      on;
tcp_nodelay     on;

keepalive_timeout  65;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

access_log /var/log/openresty/access.log;
error_log /var/log/openresty/error.log;

gzip  on;
gzip_disable "msie6";

include ../sites/default.conf;

server {
    listen 8080;
    location / {
        default_type text/html;
        content_by_lua '
            ngx.say("<p>hello, world</p>")
        ';
    }
}

}_

I am trying to terminate http on openresty and just fwd the http body to the client which connect over tcp to openresty.

I am not sure if this is version mismatch issue. Not sure if streams module works with openresty version 1.11.2.2. Can I get some help on the same?

FFI ngx_http_lua_set_req equivilent

As far as I can see there is no equivalent to getfenv(0).__ngx_req for the stream session as far as I can see implemented in the lua stream module.

I dont think I can implement this one myself, however it is a requirement for the FFI side of balancer_by_lua_* (#7)

too long string in t/009-log.t

hi,

nginx error log is limited to 2048 char, however it is easy to make longer string with

ngx.log(ngx.ERR, "a" .. string.rep("h", 1970) .. "b")

what is meaning of that test ?

are people supposed to configure nginx --with-cc-opt="-DDEBUG_MALLOC -DNGX_MAX_ERROR_STR=4096" ?

how to use the stream-lua-nginx-module to implement a route-server that dispatch the tcp stream or other private protocol stream

Hi !
I would like to use the stream-lua-nginx-module to implement a route-server that dispatch the private protocol stream.I plan to parse the stream by lua and find the rule to dispatch the stream,but,when I was programming, I was confused which phase I should do the parsing job,there is no access phase in the stream-lua-nginx-module,I can't use the access_by_lua_block directive.Could you help me to solve this problem,thank you!

access_by_lua

Hello, I see that access_by_lua is not supported, I'd be as easy as copying it from the lua-http module, at least to make a PoC or it is in some sense challenging to do? Is there another way to execute lua code with a proxy_pass directive in stream? I read that content_by_lua shouldn't be used with proxy_pass right?

Thanks a lot.

Can I share some vars to the http block

Hello I am working with the ngx_stream_ssl_preread_module and I would like to share some vars between stream and http blocks. In the http block I am using LUA, I was thinking that maybe with stream-lua I'd be able to share some data, but it looks like I can't do that. because IMHO 2 different LUA interpreters will be launched for the 2 modules. If you have any hints they'd be welcome.

Thanks,
Jeppo

error: assignment from incompatible pointer type [-Werror]

nginx1.9.15 make 编译错误,具体输出如下:
../nginx_module/stream-lua-nginx-module-0.0.1/src/ngx_stream_lua_socket_tcp.c: In function ‘ngx_stream_lua_socket_resolve_handler’:
../nginx_module/stream-lua-nginx-module-0.0.1/src/ngx_stream_lua_socket_tcp.c:819:15: error: assignment from incompatible pointer type [-Werror]
cc1: all warnings being treated as errors
make[1]: *** [objs/addon/src/ngx_stream_lua_socket_tcp.o] Error 1
make[1]: Leaving directory `/data/build/nginx-1.9.15'
make: *** [build] Error 2

操作系统:Ubuntu 12.04 LTS 64bit
nginx 版本: nginx 1.9.15
stream-lua-nginx-module 版本:stream-lua-nginx-module-0.0.1
gcc 版本: 4.6.3

configure 脚本:
./configure --prefix=/opt/nginx-1.9.15 --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-file-aio --with-stream --with-stream_ssl_module --add-module=../nginx_module/stream-lua-nginx-module-0.0.1 --with-cc-opt='-O2 -g' --with-ld-opt="-Wl,-rpath,/opt/luajit-2.0.4/lib"

@agentzh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.