nginx 日志格式为:
log_format main '$remote_addr [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$cookie_logintoken"';
我设置了 log_by_lua_file
log_by_lua_file xxxxx/ngx_lua_waf/log.lua;
和 log.lua 内容:
ngx.req.set_header("User-Agent", "this is testing User-Agent")
ngx.req.set_header("Referer", "this is testing Referer")
和 access.log 更改
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" "-" "-"
如何更改像 $request 这样的 nginx 内置变量?我想将 nginx 日志之前的“GET /test/client.php HTTP/1.1”更改为 access.log
ngx.var.request = "xxxx" 将是错误的:
failed to run log_by_lua*: xxxx/ngx_lua_waf/log.lua:15: variable "request" not changeable
但我不知道如何用 ngx.req.set_header 更改它
谁能告诉我如何改变它?