0
nginx的日誌格式是:我可以使用Lua修改內置的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內置變量?我想改變 「GET /test/client.php HTTP/1.1」 前nginx的日誌access.log的
ngx.var.request = 「XXXX」 將是錯誤:
failed to run log_by_lua*: xxxx/ngx_lua_waf/log.lua:15: variable "request" not changeable
但我不konw如何與ngx.req.set_header改變它
誰能告訴我怎麼改?
似乎只有做 – weizhao
方式,值得一提的是'set'不'htt'p上下文中有效,就應該在其他地方使用它(例如位置)。由於'log_by_lua_block'運行在nginx日誌階段,無論你使用set來定義變量都應該工作。 nit:log_by_lua_block後沒有';'。 – cuongnv23