Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a reverse proxy that l want to log request body with which currently looks lie

log_format my_tracking '"$request" "$http_soapaction" "$http_content_type" "$request_body"';

which is logging everything wonderfully, now I want to log the response body of these requests its turning out to be a lot harder. I have been trying to use the Lua module (which I've compiled into Nginx 1.3.14) but I can't find any examples of how to do this, I'm definitely stretching my technical ability so any assistance would be greatly received.

Thanks, Will Edit Reply Quote Report

share|improve this question
add comment

1 Answer

Indeed, setting variable in body_filter and then passing it into log file doesn't work. I've checked this configuration and it worked but unfortunately nginx logs data into error.log:

 error_log  logs/error.log  info;

 location / {
      set $myresponse;  #we must declare it first, we cannot create vars in lua
      proxy_pass http://mybackendserver;
      body_filter_by_lua 'ngx.var.myresponse = ngx.arg[1]
      ngx.log(ngx.INFO,ngx.var.myresponse)
      ';

    }
}

ps. Would like to know too how to log to access logs from lua module.

share|improve this answer
    
Hi, This doesn't work, it works if instead of ngx.arg[1], we put a lua string, but it won't put the body into that var. –  Reu May 8 '13 at 9:31
    
indeed, updated post, hope this one helps. –  Andrei Mikhaltsov May 8 '13 at 14:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.