Last active
June 8, 2018 12:05
-
-
Save Hendrik44/52b07cb19b983ad6ab574dae49941248 to your computer and use it in GitHub Desktop.
anonymized log format configuration for nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add this to /etc/nginx/nginx.conf in http {} block | |
map $remote_addr $ip_anonym1 { | |
default 0.0.0; | |
"~(?P<ip>(\d+)\.(\d+)\.(\d+))\.\d+" $ip; | |
"~(?P<ip>[^:]+:[^:]+):" $ip; | |
} | |
map $remote_addr $ip_anonym2 { | |
default .0; | |
"~(?P<ip>(\d+)\.(\d+)\.(\d+))\.\d+" .0; | |
"~(?P<ip>[^:]+:[^:]+):" ::; | |
} | |
map $ip_anonym1$ip_anonym2 $ip_anonymized { | |
default 0.0.0.0; | |
"~(?P<ip>.*)" $ip; | |
} | |
log_format anonymized '$ip_anonymized - $remote_user [$time_local] ' | |
'"$request" $status $body_bytes_sent ' | |
'"$http_referer" "$http_user_agent"'; | |
### use it like that ### | |
# server { | |
# ...... | |
# access_log /var/log/nginx/access.log anonymized; | |
# ...... | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment