Nginx 日志中打印 POST 请求体

Nginx About 656 words

$request_body

The variable’s value is made available in locations processed by the proxy_pass, fastcgi_pass, uwsgi_pass, and scgi_pass directives when the request body was read to a memory buffer.

配置

log_format中配置$request_body,并且在access_log中引用。

http {

    log_format upstream_pattern '$remote_addr [$time_local] [$request_time] [$upstream_response_time] "$request" $status $body_bytes_sent $request_body';

    server {
        listen 8080;
        location /api {
            access_log /tmp/nginx/access.log upstream_pattern;
            proxy_pass http://localhost:9090;
        }
    }
}

文档

https://nginx.org/en/docs/http/ngx_http_core_module.html

Views: 113 · Posted: 2025-01-06

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh