Skip to content

Instantly share code, notes, and snippets.

@hexathos
Last active February 6, 2023 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hexathos/1f46149746f770ffddcde554b9b2d81c to your computer and use it in GitHub Desktop.
Save hexathos/1f46149746f770ffddcde554b9b2d81c to your computer and use it in GitHub Desktop.
ip masking in nginx
map $remote_addr $remote_addr_anon {
~(?P<ip>\d+\.\d+)\. $ip.0.0;
~(?P<ip>[^:]+:[^:]+): $ip::;
default 0.0.0.0;
}
map $http_x_forwarded_for $http_x_forwarded_for_anon {
~(?P<ip>\d+\.\d+)\. $ip.0.0;
~(?P<ip>[^:]+:[^:]+): $ip::;
default 0.0.0.0;
}
log_format main '$remote_addr_anon - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for_anon"';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment