←back to thread

224 points gurjeet | 1 comments | | HN request time: 0.208s | 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 #
1. haik90 ◴[] No.26637879[source]
been using this for few years. As far as I know, can't return IPv4/IPv6 only from nginx without using separate server block to enforce one of them