←back to thread

980 points nkcmr | 1 comments | | HN request time: 0.205s | source
Show context
zie ◴[] No.27418112[source]
You can implement this yourself in nginx like this:

        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';
        }

and you will get back a little JSON with everything you want.
replies(1): >>27418135 #
asdfaoeu ◴[] No.27418135[source]
Doesn't seem to work right...

    {"ip": "127.0.0.1", ...}
But seriously, of course you can but 99% of people would rather just use a simple site rather than hosting their own server.
replies(1): >>27418285 #
1. zie ◴[] No.27418285[source]
Because you were doing it from localhost, the connection came from localhost. It has to be exposed out on the internet for it to return an internet IP :)

Anyways, I agree for 1 off things, whatever, use icanhazip or whatever you want, it doesn't matter if you make 1 request a day or 1 request a month... But if you are doing anything in code that uses it, you should just host it yourself and be a good net citizen.