Wednesday, August 24, 2011

Making the Web suck less


Yesterday I came across Dan Pollock’s page about hosts and I decided to try it.
First of all I was impacted by how many sites I read daily were affected. Then I was disappointed because I was noticing the lack of ads at every place I saw the “Counldn’t connect” notice. This was the exact opposite of the initial purpose.


“No Spam” by David Hegarty (flickr)
The problem is that I had my brain already trained to avoid most of the ads, but not to avoid missing web
resources. As I spend most of my computer time on Web development enabled machines, I almost always have a
webserver on. This came to my rescue in the form of a catchall location on my nginx configuration that picks
every request to localhost that is not a previously configured location, and sets a discrete and visually
avoidable 404 error page for all of them.
In case you feel tempted to follow my steps, here you have my setup:
At /opt/nginx/sites-available/spam-eater:

    server {
        listen          80 default_server;
        server_name     _;
        error_page      404 = /index.html;
        index           index.html;
        root            /path/to/no_ads;
    }

At /path/to/no_ads:

    <!DOCTYPE html>
    <html lang="es">
    <head>
    <meta charset="utf-8">
    <title>No ads</title>
    </head>
    <body>
    No ads today :-)
    </body>
    </html>