How to log all headers in nginx?

前端 未结 3 1401
醉酒成梦
醉酒成梦 2020-12-15 02:39

How do I log all the headers the client (browser) has sent in Nginx? I also want to log the response headers. Note that I am using nginx as reverse proxy.

After goi

3条回答
  •  温柔的废话
    2020-12-15 03:40

    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.

提交回复
热议问题