Nginx Return Remote IP Address
Posted by Dave Eddy on Jul 17 2018 - tags: techThe nginx server that hosts this website can now return your current IP address if you hit the url /ip.
https://www.daveeddy.com/ip
I have an alias in my bashrc to quickly use this to get my current external IP.
$ type externalip
externalip is aliased to `curl -sS https://www.daveeddy.com/ip'
$ externalip
1.2.3.4
To set this up, I modified my nginx config to add a location
section for
/ip
I basically ripped off this stackoverflow post but modified it to only match the single URL.
location =/ip {
default_type text/plain;
return 200 "$remote_addr\n";
}
location / {
root /var/www/daveeddy.com;
}