Closed mozgoo closed 4 years ago
I forgot that nginx is a proxy and tried to log the response with the proxy_pass and this also does not work, probably the issue can be closed
server {
listen 80;
server_name _;
set $response_body "-";
body_filter_by_lua_block {
if ngx.var.log_response then
ngx.var.response_body = ngx.arg[1]
end
}
location / {
access_log logs/access.log custom_access;
proxy_pass http://nginx-behind:80/;
set $log_response "1";
}
}
nginx-behind_1 | 172.18.0.2 - - [11/Dec/2019:10:48:37 +0000] "GET / HTTP/1.0" 200 612 "-" "curl/7.64.1" "-"
nginx_1 | {"scheme": "http", "host": "127.0.0.1", "local_time": "11/Dec/2019:10:48:37 +0000", "client": {"ip": "172.18.0.1", "user": "-"}, "request": {"method": "GET", "uri": "/", "body": "-", "length": 78, "protocol": "HTTP/1.1", "time": 0.000, "query": "-"}, "response": {"time": "0.010", "status": 200, "body": ""}, "headers": {"referrer": "-", "user-agent": "curl/7.64.1", "content-type": "-", "content-length": "-"}, "server": {"version": "1.15.8", "pid": 6}}
Is this a request for help? : yes
NGINX Ingress controller version: 0.26.1
Kubernetes version (use
kubectl version
): v1.14.3Environment:
What happened: I want to log response body but no success
How to reproduce it (as minimally and precisely as possible): change nginx.tmpl: added some if in body_filter_by_lua_block
and initialize variable also in nginx.tmpl:
configmap with settings:
testing backend:
In nginx-controller logs I see no
response.body
value in my custom log_formatI've tried to log response on
openresty/openresty:alpine
docker image w/o k8s and it worksconf.d/default.conf:
Please help whats wrong in my configuration Thanks