Nginx logs the contents of the server response when logging

Source: Internet
Author: User

The current nginx does not support the use of the output response newspaper style to body_filter_by_lua assign the request style to a nginx variable. Here is an example

worker_processes 1;error_log logs/error.log;events { worker_connections 1024;}http { log_format log_req_resp ‘$remote_addr - $remote_user [$time_local] ‘ ‘"$request"$status $body_bytes_sent ‘ ‘"$http_referer""$http_user_agent"$request_time req_body:"$request_body"resp_body:"$resp_body"‘; server { listen 8082; access_log logs/access.log log_req_resp; lua_need_request_body on; set $resp_body""; body_filter_by_lua ‘ local resp_body = string.sub(ngx.arg[1], 1, 1000) ngx.ctx.buffered = (ngx.ctx.buffered or"") .. resp_body if ngx.arg[2] then ngx.var.resp_body = ngx.ctx.bufferedend‘; location / { echo"Hello World!";}}}

Original address: http://www.thinksaas.cn/group/topic/347828/

Nginx logs the contents of the server response when logging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.