How to log all headers in nginx?

2019-03-23 04:38发布

As per title of this question, how do I go about logging all of the headers client browser has sent in Nginx? I also want to log response header. Note that I am using nginx as reverse proxy.

After going through documentation, I understand that I can log a specific header, but I want to log all of the headers.

I will accept hacky solution!

标签: logging nginx
2条回答
三岁会撩人
2楼-- · 2019-03-23 05:24

As @gauravphoenix said you need opnresty which comes with Lua. See https://github.com/openresty/lua-nginx-module/ for installing it. Once it's running then add in nginx

header_filter_by_lua_block {
  local h = ngx.req.get_headers()
  for k, v in pairs(h) do
    ngx.log(ngx.ERR, "Got header "..k..": "..v..";")
  end
}

Inspect your error log.

查看更多
Deceive 欺骗
3楼-- · 2019-03-23 05:26

After much research, I can conclude that it is not possible out of the box.

Update- you can use openresty which comes with Lua. Using Lua one can do pretty cool things, including logging all of the headers to say, Redis or some other server

查看更多
登录 后发表回答