Skip to content

Instantly share code, notes, and snippets.

@marcus-crane
Created July 18, 2023 23:42
Show Gist options
  • Save marcus-crane/04c55116275c0a09a96e1ff77749a64d to your computer and use it in GitHub Desktop.
Save marcus-crane/04c55116275c0a09a96e1ff77749a64d to your computer and use it in GitHub Desktop.
Basic nginx file that contains all possible log parameters in JSON format
worker_processes 2;
user www-data;
events {
use epoll;
worker_connections 128;
}
error_log /dev/stdout info;
http {
server_tokens off;
include mime.types;
charset utf-8;
log_format json_combined escape=json
'{'
'"@timestamp":"$time_iso8601",'
'"arg_name":"$arg_name",'
'"args":"$args",'
'"binary_remote_addr":"$binary_remote_addr",'
'"body_bytes_sent":"$body_bytes_sent",'
'"bytes_sent":"$bytes_sent",'
'"connection":"$connection",'
'"connection_requests":"$connection_requests",'
'"connection_time":"$connection_time",'
'"content_length":"$content_length",'
'"content_type":"$content_type",'
'"cookie_name":"$cookie_name",'
'"document_root":"$document_root",'
'"document_uri":"$document_uri",'
'"host":"$host",'
'"hostname":"$hostname",'
'"http_name":"$http_name",'
'"https":"$https",'
'"is_args":"$is_args",'
'"limit_rate":"$limit_rate",'
'"msec":"$msec",'
'"nginx_version":"$nginx_version",'
'"pid":"$pid",'
'"pipe":"$pipe",'
'"proxy_protocol_addr":"$proxy_protocol_addr",'
'"proxy_protocol_port":"$proxy_protocol_port",'
'"proxy_protocol_server_addr":"$proxy_protocol_server_addr",'
'"proxy_protocol_server_port":"$proxy_protocol_server_port",'
'"proxy_protocol_tlv_name":"$proxy_protocol_tlv_name",'
'"query_string":"$query_string",'
'"realpath_root":"$realpath_root",'
'"remote_addr":"$remote_addr",'
'"remote_port":"$remote_port",'
'"remote_user":"$remote_user",'
'"request":"$request",'
'"request_body":"$request_body",'
'"request_body_file":"$request_body_file",'
'"request_completion":"$request_completion",'
'"request_filename":"$request_filename",'
'"request_id":"$request_id",'
'"request_length":"$request_length",'
'"request_method":"$request_method",'
'"request_time":"$request_time",'
'"request_uri":"$request_uri",'
'"scheme":"$scheme",'
'"sent_http_name":"$sent_http_name",'
'"sent_trailer_name":"$sent_trailer_name",'
'"server_addr":"$server_addr",'
'"server_name":"$server_name",'
'"server_port":"$server_port",'
'"server_protocol":"$server_protocol",'
'"status":"$status",'
'"tcpinfo_rtt":"$tcpinfo_rtt",'
'"tcpinfo_rttvar":"$tcpinfo_rttvar",'
'"tcpinfo_snd_cwnd":"$tcpinfo_snd_cwnd",'
'"tcpinfo_rcv_space":"$tcpinfo_rcv_space",'
'"time_iso8601":"$time_iso8601",'
'"time_local":"$time_local",'
'"uri":"$uri",'
'}';
access_log /dev/stdout json_combined;
server {
listen 8999;
error_page 500 502 503 504 /50x.html;
location / {
return 200 'hello world!\n';
}
}
}
@marcus-crane
Copy link
Author

$ docker run --rm --name nginxlogconfig -p 8999:8999 -v ./nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
$ curl -d 'nice=cool' -X POST "http://localhost:8999/test?hello=hi"
$ docker logs <id> | grep "{" | tail -n 1 | sed 's/,}/}/g' | jq '.'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment