Skip to content

Instantly share code, notes, and snippets.

@lstellway
Created January 15, 2021 21:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lstellway/15cbe998d2625e52462563ef71533e84 to your computer and use it in GitHub Desktop.
Save lstellway/15cbe998d2625e52462563ef71533e84 to your computer and use it in GitHub Desktop.
Simple NGINX config to return real client IP address
map ":$http_x_forwarded_for" $IP_ADDR {
":" $remote_addr; # Forwarded for not set
default $http_x_forwarded_for; # Forwarded for is set
}
server {
server_name example.com;
listen 80;
listen [::]:80;
location / {
default_type application/json;
return 200 "{\"ip\": \"$IP_ADDR\"}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment