What is my fucking IP address and fun with nginx's echo module[source]
xml
<glacius:metadata> | |
<title>What is my fucking IP address and fun with nginx's echo module</title> | |
<description>How to use nginx to display the user's remote IP address</description> | |
<category>Legacy blog posts</category> | |
<category>Programming</category> | |
<category>nginx</category> | |
<category>Web servers</category> | |
</glacius:metadata> | |
<glacius:macro name="legacy blargh banner"> | |
<properties> | |
<originalUrl>https://tmont.com/blargh/2011/7/what-is-my-fucking-ip-address-and-fun-with-nginxs-echo-module</originalUrl> | |
<originalDate>2011-07-18T07:27:40.000Z</originalDate> | |
<message> | |
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. | |
</message> | |
</properties> | |
</glacius:macro> | |
<p> | |
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 | |
<a href="https://thefuckingweather.com/">the fucking weather</a> and | |
<a href="https://whatthefuckshouldimakefordinner.com/">what the fuck should I make for dinner</a> | |
which are hilarious in their vulgarity. Unfortunately, whatismyfuckingipaddress.com was already taken. | |
</p> | |
<p> | |
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 | |
<a href="https://icanhazip.com/">http://icanhazip.com/</a>), and whatismyip.com offers a similar | |
service <a href="https://automation.whatismyip.com/n09230945.asp">here</a>. | |
</p> | |
<p> | |
But just because someone else has already done something many times doesn't mean you shouldn't do it, | |
too. Right? | |
</p> | |
<p> | |
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. | |
<a href="http://remoteaddr.xyz/">And it can</a>. | |
</p> | |
<glacius:code lang="nginx"><![CDATA[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: /"; | |
} | |
}]]></glacius:code> |