Nginx json format access_log

Jbn1233
1 min readJun 20, 2020

json is more friendly with ELK. SO this is my latest setting

log_format json_combined escape=json
'{'
'"time_local":"$time_local",'
'"remote_addr":"$remote_addr",'
'"server_addr":"$server_addr",'
'"scheme":"$scheme",'
'"host":"$host",'
'"status":"$status",'
'"request_method":"$request_method",'
'"uri":"$uri",'
'"query_string":"$query_string",'
'"server_protocol":"$server_protocol",'
'"bytes_sent": $bytes_sent,'
'"body_bytes_sent": $body_bytes_sent,'
'"request_length": $request_length,'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent",'
'"request_time":"$request_time",'
'"upstream_response_time":"$upstream_response_time",'
'"upstream_addr":"$upstream_addr",'
'"http_content_type":"$sent_http_content_type"'
'}';

Output:

{
"time_local": "20/Jun/2020:09:29:21 +0700",
"remote_addr": "192.168.2.76",
"server_addr": "10.23.68.79",
"scheme": "https",
"host": "api.home.net",
"status": "401",
"request_method": "POST",
"uri": "/js-service-user/api/users/tokens",
"query_string": "",
"server_protocol": "HTTP/1.1",
"bytes_sent": 680,
"body_bytes_sent": 115,
"request_length": 2730,
"http_referrer": "",
"http_user_agent": "okhttp/3.14.2",
"request_time": "0.480",
"upstream_response_time": "0.480",
"upstream_addr": "10.18.92.213:80",
"http_content_type": "application/json; charset=utf-8"
}

PS. No need to quote on numeric variable.

--

--

Jbn1233

Very short and simple notes for CKA/SRE and may not works on your environment | jbn1233@gmail.com | Bangkok, Thailand |