What does HackerNews think of lua-nginx-module?

Embed the Power of Lua into NGINX HTTP servers

Language: C

That said, popular websites on/for Tor are free of JavaScript and they have implemented everything (such as captchas, or the "JavaScript is enabled" warning, and so forth) using pure HTML and CSS. They do use OpenResty[1], too, which is NGINX + Lua. Good stuff.

[1] https://openresty.org/, https://github.com/openresty/lua-nginx-module

Here's an example of how I'm using it. Basically to log part of the response body to API requests.

    log_format  main  '$remote_addr - - [$time_local] "$request" '
                      '$status $body_bytes_sent "$host" '
                      '"$http_user_agent" $http_content_length $request_time '
                      '"$resp_body" *$connection $connection_requests';

    server {
        set $resp_body "";
        location ~ "^/api/v1/...$" {
            # Append response to resp_body until it reaches max_len.
            # - ngx.arg[1] is input chunk.
            # - ngx.arg[2] is eof flag (response is done).
            # - ngx.ctx.resp_body holds partial result between calls
            # - ngx.var.resp_body holds final result.
            # From:
            # - https://gist.github.com/morhekil/1ff0e902ed4de2adcb7a
            # - https://github.com/openresty/lua-nginx-module/
            body_filter_by_lua_block {
                local max_len = 256
                local resp_body = (ngx.ctx.resp_body or "")
                if string.len(resp_body) <= max_len then
                    resp_body = resp_body .. string.sub(ngx.arg[1], 1, max_len)
                    ngx.ctx.resp_body = string.sub(resp_body, 1, max_len)
                end
                if ngx.arg[2] then
                    ngx.var.resp_body = ngx.ctx.resp_body
                end
            }
    }
But there are many scenarios where being able to extend the HTTP server via Lua is more convenient than writing a plugin I would think?

I've also used Lua in the past with haproxy and with Redis. It's a powerful, performant, light-weight, and flexible escape hatch/extension mechanism.

We use NGINX + Lua [1] to collect real-time diagnostic and performance data from physical machines while they operate. We collect about 150,000 data points (HTTP requests) per second with 2 NGINX servers and 2 Redis servers. We've benchmarked this particular server group up to almost a million req/s before it started to break down (median resp time > 100ms).

[1] https://github.com/openresty/lua-nginx-module

Could someone explain to me why would I choose this over https://github.com/openresty/lua-nginx-module ? It supports LuaJIT and while I suppose it is possible to write faster C code by hand than JIT translated Lua it'd be hard and I'd fear the maintainability of hand optimized C code.
LuaJIT is such an amazing piece of software - apparently to such an extent that only Mike Pall fully understands some of its internals. Besides being much faster than the official Lua VM, it offers extended features like the FFI library [1].

Kong[2] uses it extensively, by leveraging the underlying OpenResty[3] framework.

[1] http://luajit.org/ext_ffi.html

[2] https://github.com/Mashape/kong

[3] https://github.com/openresty/lua-nginx-module

This can be done with lua-nginx-module [1] and its 'balancer_by_lua' directive [2].

There are projects like the one I'm working on [3] that implement dynamic proxies using OpenResty.

[1]: https://github.com/openresty/lua-nginx-module [2]: https://github.com/openresty/lua-nginx-module#balancer_by_lu... [3]: https://github.com/3scale/apicast/

I can't speak for Apache configurations, but on-the-fly cert lookup is possible in nginx using the lua_nginx module[1] - IIRC that feature was developed by Cloudflare, to power their SSL termination.

[1]: https://github.com/openresty/lua-nginx-module/#ssl_certifica...