←back to thread

980 points nkcmr | 5 comments | | HN request time: 0s | source
Show context
OskarS ◴[] No.27415822[source]
I’ve seen packages that do ”internet-detection” by calling out to icanhazip.com, and I just thought that was so irresposnible. What if your package got popular, how much money are you costing the hoster? For services like this, people just don’t consider the fact that there’s someone on the other side.
replies(3): >>27416037 #>>27416043 #>>27416090 #
1. Seirdy ◴[] No.27416090[source]
If you want, you can set up a similar service yourself by adding the following lines to an NGINX config:

    location = /ip {
            default_type text/plain;
            return 200 '$remote_addr';
    }

Requesting "yoursite.tld/ip" will then return your IP address. I set up something like this on all my servers and recommend that others do the same. It's easy to do the same for Apache and Caddy configs. That should help spread the load.

I'm curious as to what other overused utilities can be trivially done with pure server configs.

replies(3): >>27416657 #>>27416779 #>>27418129 #
2. jacobmischka ◴[] No.27416657[source]
Is it easy to do the same for Apache? The best solution I found was some hacky way with an ErrorDocument directive which seems pretty gross.
replies(1): >>27417280 #
3. lsiebert ◴[] No.27416779[source]
Doing this for HN asks you to login as an administrator.
4. Ayesh ◴[] No.27417280[source]
You can use SSI, and echo the remote IP: https://httpd.apache.org/docs/2.4/howto/ssi.html

``` <!--#echo var="REMOTE_ADDR" --> ```

5. zie ◴[] No.27418129[source]
If you want JSON instead:

        location /ip {
                add_header Content-Type "application/json";
                return 200 '{"host":"$server_name","ip":"$remote_addr","port":"$remote_port","server_ip":"$server_addr","server_port":"$server_port"}\n';
        }