How to configure an nginx VHost to hang up on the client in the rudest possible way?

smitelli asked:

I have a, let’s call it, “legacy” VHost configured on an nginx server. It used to be a full site, but it has since been decommissioned and all the content removed. The server block now looks something like this:

server {
    listen 80;
    server_name defunct-site.com;
    return 410;
}

There are DNS records and applications which are out of my control that still point to this server, and it still gets relatively significant traffic despite my pleads to the third party to update their configuration and stop trying to hit the site. Needless to say, I can’t change my IP address without significant pointless effort.

Is there a stronger way to tell these clients that their traffic is no longer welcome here? The source IPs are all over the place, so doing a successful iptables block seems unlikely. And I need to read enough of the HTTP request to get to the Host: header to make sure I’m not clobbering traffic intended for a legitimate VHost.

My answer:


410 Gone is the canonical error to return for content which no longer exists and is known to never be returning. In particular, it also tells search engines this, so that they can lower the ranking of, or delist, such URLs.

One additional thing you can do is to provide an error_document for it, to explain to people who visit the site what is going on. Without it, all they will see is an uninformative “410 Gone”. For instance:

error_document 410 /410.html;

This will be just a static HTML document that contains whatever you wish, and you can be as rude as you like.

<html>
<head><title>Gone</title></head>
<body>
<h1>Go away</h1>
<p>You aren't supposed to be here. This is Initech's fault, yell at
John Doe on +1 212 555-1234.</p>
</body>
</html>

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.