Hello,
I'm running the latest Openresty version (1.11.2.3) and am using it as a reverse-proxy. I'm currently implementing a custom logging routine using
https://github.com/cloudflare/lua-resty-logger-socket, which works fine.
However, while doing all sorts of tests, I noticed that if Nginx throws a 400 error (generated on purpose with Curl) the log_by_lua routine is not executed in the "location" block which should serve the request.
Here is my simplified config snippet :
server {
location / {
log_by_lua_block {
ngx.log(ngx.ERR, "Testing log_by_lua")
}
proxy_pass 1.2.3.4:8080
}
}
When generating a 400 error with :
myheader=$(python -c "print 'A'*100000")
curl --header "X-MyHeader: $myheader" '
http://1.2.3.4'
The traditionnal access_log file is correctly written and I can see the request :
[...] "GET / HTTP/1.1" 400 242 "-" "curl/7.38.0" "-" [...]
But log_by_lua is not executed and I can't see my test message. It only works by duplicating the log_by_lua code in the "server" section of the config.
I read the Openresty docs and saw
https://github.com/openresty/lua-nginx-module#missing-data-on-short-circuited-requests which states that "Nginx may terminate a request early [...] This means that phases that normally run are skipped, such as the rewrite or
access phase. This also means that later phases that are run regardless, e.g.
log_by_lua, will not have access to information that is normally set in those
phases".
If I understand correctly, as the request is terminated early, any LUA code present in the "location /" block will not be executed because some phases are skipped ?
Thanks for your input !