发布于 5年前

Nginx日志如何记录post参数

系统默认的日志格式为

'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

添加post参数,只需增加 $request_body 即可。

nginx.confhttp下 添加或调整 log_format new_format 信息

http
    {
        ...

        log_format new_format '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$request_body" "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

        ...

    server
    {
        ...
    }
    include 相关路径/vhost/myweb.conf;
}

/vhost/myweb.confaccess_log 的最后添加 new_format

server
{
    ...
    access_log  /www/logs/myweb.log new_format;
    ...
}

保存重启 nginx 服务,生效后可使用 tail -f /www/logs/myweb.log 实时查看log信息

©2020 edoou.com   京ICP备16001874号-3