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