←back to thread

224 points gurjeet | 1 comments | | HN request time: 0.234s | 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. rogerdonut ◴[] No.26637327[source]
This can also be done with HAProxy

    listen whatismyip
        bind :::80 # listen on ipv4/ipv6
        bind :::443 ssl crt /etc/haproxy/ssl/fullchain.pem
        mode http

        http-request return status 200 content-type "text/plain" lf-string "%[src]" if { path /ip }
        http-request return status 200 content-type "application/json" lf-string "{\"ip\":\"%[src]\"}" if { path /json_ip }
        http-request deny