Skip to content

Instantly share code, notes, and snippets.

@shoeb751
Forked from morhekil/nginx.conf
Last active Apr 14, 2021
Embed
What would you like to do?
Full request/response body logging in nginx
http {
server {
listen 1.2.3.4;
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
end
';
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;
proxy_pass http://127.0.0.1:3000;
access_log /var/log/nginx/server.log bodylog;
}
}
}
@mallikharjunrao
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.

Loading

@thinkingerrol
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.

https://stackoverflow.com/questions/26874828/set-directive-is-not-allowed-here
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#set

Loading

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