←back to thread

224 points gurjeet | 1 comments | | HN request time: 0.225s | 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 #
0xbkt ◴[] No.26637665[source]
It is even easier with Caddy's `respond` directive[0], placeholders[1], and automatic HTTPS.

Caddyfile:

  example.com {
      respond "{remote_host}"
  }
[0] https://caddyserver.com/docs/caddyfile/directives/respond

[1] https://caddyserver.com/docs/caddyfile/concepts#placeholders

replies(1): >>26644356 #
1. BrandoElFollito ◴[] No.26644356[source]
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.