Make json log for loki

This commit is contained in:
Dryusdan 2024-03-25 16:19:46 +01:00
parent 617751918d
commit bc0f497c13
5 changed files with 39 additions and 0 deletions

View File

@ -45,6 +45,7 @@
- git
- libpython3-dev
- zlib1g-dev
- geoip-database
tags:
- install
- reconfigure

View File

@ -99,6 +99,41 @@ http {
image/svg+xml;
{% endif %}
map $http_referer $httpReferer {
default "$http_referer";
"" "(direct)";
}
map $http_user_agent $httpAgent {
default "$http_user_agent";
"" "Unknown";
}
map $geoip_country_code $geoIP {
default "$geoip_country_code";
"" "Unknown";
}
geoip_country /usr/share/GeoIP/GeoIP.dat;
log_format json_analytics escape=json '{'
'"request_id": "$request_id", '
'"server_name": "$server_name", '
'"request_uri": "$request_uri", '
'"request_time": "$request_time", '
'"http_referer": "$httpReferer", '
'"http_user_agent": "$httpAgent", '
'"remote_addr": "$remote_addr", '
'"http_x_forwarded_for": "$http_x_forwarded_for", '
'"status": "$status", '
'"bytes_sent": "$bytes_sent", '
'"time_local": "$time_local", '
'"ssl_protocol": "$ssl_protocol", '
'"ssl_cipher": "$ssl_cipher", '
'"geoip_country_code": "$geoIP"'
'}';
{% if nginx_modsecurity is defined %}
modsecurity on;
modsecurity_rules_file /etc/nginx/modsecurity_includes.conf;

View File

@ -8,6 +8,7 @@ server {
index {{ item.index|default('index.html index.htm')}};
access_log /var/log/nginx/{{ item.server_name[0] }}.access.log combined buffer=20m flush=5m;
access_log /var/log/nginx/{{ item.server_name[0] }}.access.json.log json_analytics;
error_log /var/log/nginx/{{ item.server_name[0] }}.error.log warn;
{% include 'partials/ssl.j2' %}

View File

@ -8,6 +8,7 @@ server {
index {{ item.index|default('index.html index.htm')}};
access_log /var/log/nginx/{{ item.server_name[0] }}.access.log combined buffer=20m flush=5m;
access_log /var/log/nginx/{{ item.server_name[0] }}.access.json.log json_analytics;
error_log /var/log/nginx/{{ item.server_name[0] }}.error.log warn;
{% include 'partials/ssl.j2' %}

View File

@ -5,6 +5,7 @@ server {
{% include 'partials/header.j2' %}
access_log /var/log/nginx/{{ item.server_name[0] }}.access.log combined; # buffer=20m flush=5m;
access_log /var/log/nginx/{{ item.server_name[0] }}.access.json.log json_analytics;
error_log /var/log/nginx/{{ item.server_name[0] }}.error.log;
include /etc/nginx/conf.d/proxy.conf;