the nginx log format is :
log_format main '$remote_addr [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$cookie_logintoken"';
I set the log_by_lua_file
log_by_lua_file xxxxx/ngx_lua_waf/log.lua;
and log.lua content:
ngx.req.set_header("User-Agent", "this is testing User-Agent")
ngx.req.set_header("Referer", "this is testing Referer")
and access.log change
127.0.0.1 [17/Dec/2016:16:21:47 +0800] "GET /test/client.php HTTP/1.1" 200 1370 "this is testing Referer" "this is testing User-Agent" "-" "-"
how can I change the nginx build-in var like $request ? I want to change the "GET /test/client.php HTTP/1.1" before nginx log to access.log
ngx.var.request = "xxxx" will be error :
failed to run log_by_lua*: xxxx/ngx_lua_waf/log.lua:15: variable "request" not changeable
but I dont konw how to change it with ngx.req.set_header
can anyone tell me how to change it?
You can modify several embedded Nginx variables using the Nginx Lua but the embedded request variable
cannot
be modified.Actually, your starting assumption should be that embedded variables cannot, or, perhaps more accurately, should not, be modified.
Whenever you need a modified version of an embedded variable, define a custom variable, make your changes to that custom variable, and use this instead.
In your specific case: