nginx
nginx copied to clipboard
Creating custom access logs in JSON format
I am trying to create custom access logs in JSON format. I initially tried updating the config map hhtp-snippet but it doesnt work. The nginx.conf file is not updated and the /var/log/nginx/json_access.log file is not created.
How do I achieve this?
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
namespace: nginx-ingress
data:
ssl-session-cache: "True"
ssl-session-cache-size: 10m
ssl-session-timeout: 10m
# stream-snippets: |
map-hash-bucket-size: "512"
map-hash-max-size: "2048"
ssl-ciphers: HIGH:!aNULL:!MD5
ssl-protocols: TLSv1.2 TLSv1.3
keepalive-timeout: "80"
keepalive-requests: "300"
keepalive: "32"
server-tokens: "False"
worker-connections: "4096"
http-snippet: |
log_format json_analytics escape=json '{'
'"msec": "$msec", '
'"connection": "$connection", '
'"connection_requests": "$connection_requests", '
'"pid": "$pid", '
'"request_id": "$request_id", '
'"request_length": "$request_length", '
'"remote_addr": "$remote_addr", '
'"remote_user": "$remote_user", '
'"remote_port": "$remote_port", '
'"time_local": "$time_local", '
'"time_iso8601": "$time_iso8601", '
'"request": "$request", '
'"request_uri": "$request_uri", '
'"args": "$args", '
'"status": "$status", '
'"body_bytes_sent": "$body_bytes_sent", '
'"bytes_sent": "$bytes_sent", '
'"http_referer": "$http_referer", '
'"http_user_agent": "$http_user_agent", '
'"http_x_forwarded_for": "$http_x_forwarded_for", '
'"http_host": "$http_host", '
'"server_name": "$server_name", '
'"request_time": "$request_time", '
'"upstream": "$upstream_addr", '
'"upstream_connect_time": "$upstream_connect_time", '
'"upstream_header_time": "$upstream_header_time", '
'"upstream_response_time": "$upstream_response_time", '
'"upstream_response_length": "$upstream_response_length", '
'"upstream_cache_status": "$upstream_cache_status", '
'"ssl_protocol": "$ssl_protocol", '
'"ssl_cipher": "$ssl_cipher", '
'"scheme": "$scheme", '
'"request_method": "$request_method", '
'"server_protocol": "$server_protocol", '
'"pipe": "$pipe", '
'"gzip_ratio": "$gzip_ratio", '
'"geoip_country_code": "$geoip_country_code"'
'}';
geoip_country /etc/nginx/GeoLite2-Country.mmdb {
$geoip_country_code default=US source=$remote_addr country iso_code;
}
access_log /var/log/nginx/json_access.log json_analytics;