Skip to content

Instantly share code, notes, and snippets.

Forked from morhekil/nginx.conf
Last active Apr 14, 2021
What would you like to do?
Full request/response body logging in nginx
http {
server {
log_format bodylog '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" $request_time '
'<"$request_body" >"$resp_body"';
set $resp_body "";
lua_need_request_body on;
body_filter_by_lua '
local resp_body = ngx.arg[1]
ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_body
if ngx.arg[2] then
ngx.var.resp_body = ngx.ctx.buffered
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
access_log /var/log/nginx/server.log bodylog;
Copy link

mallikharjunrao commented Aug 22, 2017

@shoeb751 getting the exception: "set" directive is not allowed here in ~ /nginx/conf/nginx.conf
any solution? this configuration used for default nginx.conf also help me how to configure for multihost config and seperate logs for l hosts.

Thank you very much.


Copy link

thinkingerrol commented Apr 14, 2021

@mallikharjunrao it is probably too late to answer you after 4 years but for the record: "set" directive can only be used in "server", "location" and "if" blocks. This has already been fixed in this gist.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment