6 ms·
For ridiculously easy things like this, I think it's smarter for you to just host it yourself. This way you are not forcing other people to carry your burden.
by zie 3y ago
For ridiculously easy things like this, I think it's smarter for you to just host it yourself. This way you are not forcing other people to carry your burden.
nginx config example:
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';
}
Which will return something like this in JSON format:
{"host":"www.example.org","ip":"199.200.200.14","port":"7990","server_ip":"199.200.100.229","server_port":"443"}
This is all done 100% within NGINX, and I include a lot of stuff you probably don't want or care about. Other web servers probably have similar capabilities.
- nurettin 3y agoI have something very similar, and all my projects depend on that. I also made a copy of httpbin which I host on a server. Useful for unit testing. And a gateway for hookback urls that I use for relaying/logging oauth and similar things to internal vpns. All very useful gadgets that have been running for over half a decade on arch.
- turtlebits 3y agoIf it's on the public internet, you're not forcing anyone to provide you a service. Standing up reliable infra isn't easy nor free, no matter how trivial deploying it may be.
- iknowstuff 3y agoProbably more efficient to use https://lib.rs/hyper https://lib.rs/hyper - and actually maintainable.
- jesprenj 3y agoI can't say a thing about efficiency, but for maintainability, I have to disagree. This seems to be a rust library, and for maintaining that, you'd need to write a program, compile it every time some updates come by, rerun the recompiled program, ... With the parent comment example, all you need is nginx, available as a package on all distros, and a single static config file. With an auto-updating package manager and a service manager, one never needs to write anything else apart from that static config file. Or did you mean something else with "actually maintainable"?
- lmm 3y agoI would trust the rust compile/rerun process a lot more than an auto-updating linux distribution, personally. Sooner or later that auto-updating package manager will break your config file, itself, or both.
- noirscape 3y agoThe majority of nginx distributions will not get any major bumps during the lifetime of the distros they're in. Whether that's because the distro itself has policies against that (Debian, Ubuntu) or because the distro version expires before nginx' stable release does (most of the ones with a higher update frequency, ie. Fedora) so by the time the version expires, they can just go to the next stable version on the release after. This is pretty much only a risk if your distro is completely rolling release and even those in my experience at least offer an "lts" package of some sort. So that's not a problem. Besides the majority of nginx setups don't rely on too fancy things; most of the stuff that gets changed in updates that affect config files are the fancier nginx modules.
- lmm 3y ago> The majority of nginx distributions will not get any major bumps during the lifetime of the distros they're in. Whether that's because the distro itself has policies against that (Debian, Ubuntu) or because the distro version expires before nginx' stable release does (most of the ones with a higher update frequency, ie. Fedora) so by the time the version expires, they can just go to the next stable version on the release after. If you're following that approach then having auto updates enabled is kind of irrelevant/meaningless; at some point you're going to be running a very old (and unsupported) version of your distro with all that that implies.
- jesprenj 3y agoThat is true, yeah. But the library in question will also eventually break the existing API / stop supporting compatible releases with security patches. I assume this nginx config will still work for many releases in the future.
- Titan2189 3y agoThis will return the wrong results when used behind a load balancer
- justsomehnguy 3y agoAnything would return proxy/LB address. So do not use it behind LB/proxy/NAT.
- xereeto 3y agoNot if you use the PROXY protocol
- linsomniac 3y agoOk, I'll bite... What kind of machine do you host this on that can handle 400,000 of these requests (with TLS mind you) per second? That was the load he mentions it handling in 2021, he stopped mentioning requests per day metrics after that.
- BeefWellington 3y ago400,000 req/s is actually not crazy. Back in the single-core era I was doing 1/10th of that on a production server for similar workloads a compiled VB / COM+ app. I would wager Nginx can handle that pretty easily on a modern dual or quad-core system.
- metadat 3y agoThe thing is, at that rate, you'll likely run out of ports without more advanced / exotic TCP configurations. .. Ain't 65536 a capital B. Edit: @toast0: valid point, thanks for the correction.
- toast0 3y agoTcp connections are a 4-tuple {PeerAIP, PeerBIP, PeerAPort, PeerBPort}, if you hold your IP and port fixed, because you only listen on port 443, you can do 64k connections to each other peer's IP... if the other peer can manage to use them all. Chances are you'll never run into that limit for this service, because even if there's a ton of users behind the same IP due to NAT, they don't need to hold long sessions, and you can disable http keep-alive and close connections right away. Chances are you'll have some ip diversity in 400k requests/second though.
- hamandcheese 3y agoI think you are misunderstanding... the point of self hosting is that you only need to handle your own load. It only needs to scale to what, 1 request per day?
- noirscape 3y agoWasn't the original target of nginx back in the nineties to hit 100k requests per second with less overhead than (at the time, standard) apache2? With that in mind + the general advancing of hw since then, it wouldn't be too suprising if nginx could handle that load easily. It'd just get more difficult if you wanted to put anything else (ie. metrics) on that endpoint since afaict nginx doesn't have anything to monitor those things if you don't have the Enterprise version of their tools. In any case you might be misreading the setup for the parent here - the recommendation is just that if you're doing this in the context of a webapp, that this sort of behavior is trivially easy to bounce back in JSON using nginx.
- francislavoie 3y agoAlternatively, with Caddy (with automated TLS, single static binary): example.com { handle /ip { header Content-Type application/json respond `{"host":"{host}","ip":"{remote_host}","port":"{remote_port}"}` } } Though the usefulness of the host (client specified it), remote port (it's random), and server ip/port (it's static and not useful for the client) are questionable.
- quickthrower2 3y agoUseful for UA sanity checking I guess
- anon7331 3y agoAlternatively, search the web for everyone implementing "/ip" and random load balance between all of them and let them handle the load for you.
- gaudat 3y agoMy favorite: https://cloudflare.com/cdn-cgi/trace https://cloudflare.com/cdn-cgi/trace
- matthberg 3y ago/cdn-cgi/trace isn't available on just cloudflare.com, it's on every site they proxy too (there might be a setting somewhere to disable it yet it's on by default). I've yet to figure out what happens if your site also serves something there, yet it was surprising to see on a barebones site I had routed through them. I learned this from: https://news.ycombinator.com/item?id=36383258 https://news.ycombinator.com/item?id=36383258
- e28eta 3y agoTIL. Looks like they have it documented (since Apr 2022, based on the github history), it cannot be modified or customized, and that it sometimes causes problems with SEO crawlers! https://developers.cloudflare.com/fundamentals/get-started/reference/cdn-cgi-endpoint/ https://developers.cloudflare.com/fundamentals/get-started/r...
- 1vuio0pswjnm7 3y agosni=plaintext There was a great trial CF ran for a long period with a previous version of encrypted SNI (now ECH). One could get encrypted SNI with any site using CF via modified OpenSSL. But they stopped this experiment. Meanwhile ECH was still not ready. If anyone is getting something other than "sni=plaintext" for a CF domain besides crypto.cloudflare.com, then please let us know how.
- progbits 3y agoIsn't ECH still off by default in most browsers? The latest info I could find has it implemented but opt-in behind experimental flag in both Firefox and Chrome, and not supported at all in Safari.
- 1vuio0pswjnm7 3y ago
- 1vuio0pswjnm7 3y agoAnother one https://whatismyip.akamai.com/advanced?debug https://whatismyip.akamai.com/advanced?debug https://ipv4.whatismyip.akamai.com https://ipv4.whatismyip.akamai.com DNS-based drill whoami.akamai.net The second one might be useful to verify one is not using local, ISP-provided DNS, or to see whether a DoH provider effectively geolocates its users, e.g., Cloudflare.
- sublinear 3y agoBad cert. The common name does not match the subdomain.
- 1vuio0pswjnm7 3y agoCertificate says CN is a248.e.akamai.net CNAME for whatismyip.akamai.com is a1524.g.akamai.net Probably no certitifcate that lists whatismyip.akamai.com
- mr-karan 3y agoAnother DNS based one: dig ip @dns.toys +short
- deleted 3y ago[deleted]
- 1vuio0pswjnm7 3y agoAnother one Send a request to stackexchange.com or any of its subdomains without a user-agent header.
- acidburnNSA 3y agoNow I just need the apache config for this...anyone?
- paravz 3y agogreat callout! A more advanced self hosted option can be https://github.com/mpolden/echoip https://github.com/mpolden/echoip