What is my fucking IP address and fun with nginx's echo module
This article was originally published in my blog (affectionately referred to as blargh) on . The original blog no longer exists as I've migrated everything to this wiki.
The original URL of this post was at https://tmont.com/blargh/2011/7/what-is-my-fucking-ip-address-and-fun-with-nginxs-echo-module. Hopefully that link redirects back to this page.
The original site was at remoteaddr.info, but once that expired it was more expensive to renew, so I moved the functionality to remoteaddr.xyz.
Excuse the language, but it's a lamentation I've uttered many times while navigating to whatismyip.com and being bombarded with ads and superfluous text when all I want is at most 15 characters. It's also in reference to sites like the fucking weather and what the fuck should I make for dinner which are hilarious in their vulgarity. Unfortunately, whatismyfuckingipaddress.com was already taken.
I decided I was going to create a "competitor" to whatismyip.com because that site sucks. But mostly because it's something so simple that it shouldn't require navigating a bunch of text and ads. Of course, as it turns out, numerous sites already do that (like http://icanhazip.com/), and whatismyip.com offers a similar service here.
But just because someone else has already done something many times doesn't mean you shouldn't do it, too. Right?
But I didn't want to bootstrap some server-side language runtime for something as simple as displaying an IP address. Surely that could be done directly from the server. And it can.
server {
listen 80;
server_name remoteaddr.xyz www.remoteaddr.xyz;
gzip off;
location = / {
default_type text/plain;
echo $remote_addr;
if ($remote_addr != $proxy_add_x_forwarded_for) {
echo $proxy_add_x_forwarded_for;
}
expires 1d;
}
location = /about {
default_type text/html;
echo "<html>";
echo "<head>";
echo "<title>about remoteaddr.xyz</title>";
echo "</head>";
echo "<body>";
echo '<pre>created by <a href="https://tmont.com/">Tommy Montgomery</a> using the <a href="https://wiki.nginx.org/HttpEchoModule">nginx echo module</a>.</pre>';
echo "</body>";
echo "</html>";
}
location = /robots.txt {
default_type text/plain;
echo "User-Agent: *";
echo "Allow: /about";
echo "Disallow: /";
}
}