For the benefit of anyone interested: for a "self-hosted" solution, you can do this entirely within Nginx. Here's an example config:
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 default_server;
listen [::]:443 default_server;
# Use Letsencrypt for SSL. This part will depend on your own setup.
ssl_certificate /etc/letsencrypt/live/<my domain>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<my domain>/privkey.pem;
server_name <my domain>;
# Deny all access at all paths; useful if you're hosting other stuff behind
# the same Nginx server (e.g. reverse proxy)
location / {
deny all;
}
# At /ip, return 200 with the client IP address in the body
location = /ip {
default_type text/plain;
return 200 '$remote_addr';
}
}
One more reason to love that extraordinary web server. It is really wonderful, sad that it is not more used.
I work in IT (was a sysadmin for years, still administer my own servers) and I hated the configuration of the web servers (first Apache, then nginx) - mostly because I was too lazy to read the docs from beginning to end.
This changed with caddy. It is simple, fast, reliable, HTTPS first with LE. Great.
That's exactly what I use it for. I have a small program on my laptop that makes a request of my lambda every now and then (and if it senses a change of the network). It triggers a change in the firewall rules for a SSH server.
Between that and Mosh, I barely even notice when I change networks.
this service does a lot more than just return your remote_ip, which wont work behind a load-balancer or other proxy unless you configure realip module. and also need to add geoip module to do all the location stuff
That said, do you know of any software library that exposes the Geoip database (or at least Geoip Lite which you one easily obtain for free) in a nice API? Like how a lot of programming languages have tzinfo/tzdata libraries for querying the Tz database.
I should clarify that I was looking for an "offline" API/library that I can use against a local copy of the Lite database, but this is great stuff too.
I thought maxmind has some kind of terms change that forced account signup and some other issues 'because of some privacy law' like gdpr - maybe the Cali one?
So it has ruined my second favorite wordpress security plugin - and MaxMind not really usable like it once was (?)
For the benefit of anyone interested: for a "self-hosted" solution, you can do this entirely within Nginx. Here's an example config: