Skip to content

Instantly share code, notes, and snippets.

@brodygov
Created August 28, 2017 23:30
Show Gist options
  • Save brodygov/7cee5deb99dc9754c645d03cfccf4581 to your computer and use it in GitHub Desktop.
Save brodygov/7cee5deb99dc9754c645d03cfccf4581 to your computer and use it in GitHub Desktop.
Nginx realip module $lb_if_proxied variable: "-" if proxied, otherwise the load balancer's IP address
# Create new variable $lb_if_proxied.
#
# With the realip module enabled, $remote_addr will be the end-user's IP
# address, potentially from X-Forwarded-For, and $realip_remote_addr will be
# the actual immediate client IP address.
#
# Return the load balancer IP address ($realip_remote_addr) if the request
# looks like it was proxied. If the request does not look like it was proxied
# (when $remote_addr is a private IP address), then return "-" instead.
map $remote_addr $lb_if_proxied {
"~^127\." "-";
"~^10\." "-";
"~^172\.1[6-9]\." "-";
"~^172\.2[0-9]\." "-";
"~^172\.3[0-1]\." "-";
"~^192\.168\." "-";
default $realip_remote_addr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment