Capture full request/response body logging in nginx configured in reverse proxy mode reports nginx: [emerg] unknown directive "log_by_lua_block"

Kaushal Shriyan kaushalshriyan at gmail.com
Mon Dec 18 16:54:14 UTC 2023


Hi,

I am running nginx version: nginx/1.24.0 as reverse proxy on CentOS Linux
release 7.9.2009 (Core). I have the below config
file /etc/nginx/conf.d/microservice.conf
I want to capture full request/response body logging in nginx.

# cat /etc/nginx/conf.d/microservice.conf
    server {
        listen 80;
        server_name 192.168.0.129;

        location / {
            # Capture request headers and body
            log_by_lua_block {
                ngx.var.request_headers = ngx.req.raw_header()
                ngx.var.request_body = ngx.req.get_body_data()
            }

            # Your regular location configuration here

            # Capture response headers and body
            body_filter_by_lua_block {
                local resp_body = ngx.arg[1]
                ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_body
                if ngx.arg[2] then
                    ngx.var.resp_body = ngx.ctx.buffered
                end
            }
        }
#nginx -t
*nginx: [emerg] unknown directive "log_by_lua_block" in*
/etc/nginx/conf.d/microservice.conf:8
nginx: configuration file /etc/nginx/nginx.conf test failed

Please guide me. Thanks in advance.

Best Regards,

Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20231218/b966d555/attachment.htm>


More information about the nginx mailing list