From 7660d36f8730a24518901d29a84ca4cfc27220c7 Mon Sep 17 00:00:00 2001 From: will Date: Thu, 23 Feb 2023 12:55:15 -0700 Subject: [PATCH] New blog post: Guide - How to Block User Agents With Nginx Also updated style.css for this blog post --- blog/blog.atom | 8 ++ .../index.html | 75 +++++++++++++++++++ .../nginx.svg | 2 + style.css | 15 +++- 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 blog/posts/guide_blocking_user_agents_nginx/index.html create mode 100644 blog/posts/guide_blocking_user_agents_nginx/nginx.svg diff --git a/blog/blog.atom b/blog/blog.atom index 73f9464..7d372fc 100644 --- a/blog/blog.atom +++ b/blog/blog.atom @@ -8,6 +8,14 @@ Will https://isopod.cool/ + + Guide - How to Block User Agents With Nginx + guide_blocking_user_agents_nginx + + 2023-02-23T00:00:00+00:00 + 2023-02-23T00:00:00+00:00 + How to configure Nginx to tell Cloudflare and their shitty centralized Fediverse server to go fuck themselves. And other unwelcome stuff too, I guess. + Guide - Things I Keep Having To Google guide_things_i_keep_having_to_google diff --git a/blog/posts/guide_blocking_user_agents_nginx/index.html b/blog/posts/guide_blocking_user_agents_nginx/index.html new file mode 100644 index 0000000..609fe01 --- /dev/null +++ b/blog/posts/guide_blocking_user_agents_nginx/index.html @@ -0,0 +1,75 @@ + + + + + Guide - How to Block User Agents With Nginx + + + + +

guide:

+

How to Block User Agents With Nginx

+ +

Recently, Cloudflare has launched a clumsy, poorly-executed attempt to centralize the fediverse on their platform known as Wildebeest. There are a few reasons not to want to use it, and you probably don't want to be federating with it either. However, blocking every instance running it on sight would be both tedious and ineffective.

+

The way I've chosen to deal with this is to just configure my reverse proxy, Nginx, to deny connections from anything with "wildebeest" in the user agent string. There are several other good reasons to do this, such as blocking bots that ignore robots.txt, or adapting this approach to serve specialized pages to old browsers, or just denying access to anything that isn't Chrome if you want to earn your place in the 9th circle of Hell.

+

I'm assuming here that you already know the basics of configuring Nginx, otherwise this article won't really be of much use to you.

+

How to do it

+

Paste this into the main server block of your Nginx config to instantly drop the connection to any client with a "Wildebeest" (case insensitive) user agent:

+ +

/etc/nginx/sites-available/yoursite

+ if ($http_user_agent ~* (wildebeest)) {
+     return 444;
+ } +
+

More configuration

+

If all you want is to block Wildebeest and forget about it, you can leave now. If you want to customize this behavior further, read on.

+

Different HTTP responses

+

444 is a custom response code in Nginx that just drops the connection immediately. You can use any other HTTP error code you like, for example to return a 403 Forbidden error:

+ + return 403; + +

To issue a permanent redirect to some other URL:

+ + return 301 https://example.org/; + +

Or just to be silly :3

+ + return 418; + +

Block multiple user agents

+

You can also block multiple user agents in one statement like so:

+ +

/etc/nginx/sites-available/yoursite

+ if ($http_user_agent ~* (wildebeest|googlebot)) {
+     return 444;
+ } +
+

Includes

+

One thing I'd recommend doing is moving all your user agent blocks to a separate file that you can include in all your Nginx sites. I place this file at /etc/nginx/includes/bans:

+ +

/etc/nginx/includes/bans

+ if ($http_user_agent ~* (wildebeest|googlebot)) {
+     return 444;
+ } +
+ +

/etc/nginx/sites-available/yoursite

+ include /etc/nginx/includes/bans; +
+

The include statement goes in your server block as before.

+ + diff --git a/blog/posts/guide_blocking_user_agents_nginx/nginx.svg b/blog/posts/guide_blocking_user_agents_nginx/nginx.svg new file mode 100644 index 0000000..27062a8 --- /dev/null +++ b/blog/posts/guide_blocking_user_agents_nginx/nginx.svg @@ -0,0 +1,2 @@ + +file_type_nginx \ No newline at end of file diff --git a/style.css b/style.css index 2ddd188..494dbb8 100644 --- a/style.css +++ b/style.css @@ -139,13 +139,26 @@ code { background-color: black; padding: 0.15rem; } -main > code, body > code { +:is(main,body) > code { display: block; width: 32rem; margin: auto; + margin-bottom: 1rem; padding: 0.7rem; border: 1px solid #00ffd5; } +:is(main,body) > code > h4 { + margin: -0.7rem; + margin-top: -0.4rem; + margin-bottom: 0.7rem; + padding-bottom: 0.2rem; + font-weight: normal; + top: 0; + left: 0; + right: 0; + text-align: center; + border-bottom: 1px solid #00ffd5; +} tr:hover { background-color: #2222227c; }