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 going through documentation, I understand that I can log a specific header, but I want to log all of the headers.
I don't know if it's a new feature since the OP asked the question, but you can simply turn on debug level logging, and NGINX will log all request headers (plus a whooole lot more) to the error log. I wouldn't leave this enabled, since (1) it may log sensitive data and (2) it will fill up your disk very quickly.
Configure NGINX access log By default, the access log is located at /var/log/nginx/access. log , and the information is written to the log in the predefined combined format. You can override the default settings and change the format of logged messages by editing the NGINX configuration file ( /etc/nginx/nginx.
Enabling the error log The NGINX error log should be enabled by default. However, if this is not the case, you can enable it manually in the relevant NGINX configuration file (either at the http , server , or location levels) using the error_log directive. error_log /var/log/nginx/error.
The default log format in nginx is called "combined".
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
As @gauravphoenix said you need openresty 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..": "..toString(v)..";") end }
Inspect your error log.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With