nginx日志输出自定义header头字段

nginx版本为1.1.19,以下是具体的log配置:

log_format main '$remote_addr - $remote_user [$time_local] $http_token $http_have_deleted "$request" ' 

'$status $request_time $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

 

通过配置可以看出,可在自定义header字段前加http_,即可将指定的自定义header字段打印到log中。

像have-deleted这种带横线的字段,需要写成have_deleted,nginx会自动做处理的。 有一点需要注意:我的nginx版本是1.1.19!!!

我写这篇博客的时候,nginx最新版本是1.9.7,根据官方文档说明,要想打印自定义的header字段,需要在字段前加sent_http_,所以一定要注意nginx的版本!! 最后附上nginx1.9.7的文档: http://nginx.org/en/docs/http/ngx_http_log_module.html

posted @ 2021-09-09 17:06  非著名JAVA程序员  阅读(2360)  评论(0)    收藏  举报