←back to thread

224 points gurjeet | 1 comments | | HN request time: 0.207s | source
Show context
nerdponx ◴[] No.26634782[source]
It's great to have services like this.

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';
      }
    }
replies(7): >>26634946 #>>26636981 #>>26637327 #>>26637356 #>>26637665 #>>26637879 #>>26640213 #
VWWHFSfQ ◴[] No.26634946[source]
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
replies(2): >>26635073 #>>26643238 #
nerdponx ◴[] No.26635073[source]
Good points both.

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.

replies(2): >>26636140 #>>26637406 #
cryvate1284 ◴[] No.26636140[source]
Maxmind do APIs for a bunch of language. I've used the python one and it works well (with Lite), but see here their list:

https://dev.maxmind.com/geoip/geoip2/web-services/

replies(2): >>26636438 #>>26641833 #
nerdponx ◴[] No.26636438[source]
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.
replies(2): >>26637238 #>>26638565 #
1. cryvate1284 ◴[] No.26638565[source]
If you click through one of the links (e.g. Python) you will see it does allow you to do so!

https://pypi.org/project/geoip2/