Skip to content

Instantly share code, notes, and snippets.

@phunehehe
Last active December 12, 2015 07:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phunehehe/4737273 to your computer and use it in GitHub Desktop.
Save phunehehe/4737273 to your computer and use it in GitHub Desktop.
Block weird requests coming from stupid spiders

Nginx

set $stupid_spider "";

# If the request comes from one of these stupid spiders
if ($http_user_agent ~* (stupid|spider)) {
    set $stupid_spider "1";
}

# And if it contains these weird characters
if ($uri ~ (\(|\)|\;|:|\+)) {
    set $stupid_spider "${stupid_spider}1";
}

# Then we block it here
if ($stupid_spider = "11") {
    return 404;
}

Apache

<LocationMatch "(\(|\)|\;|:|\+)">
    SetEnvIfNoCase User-Agent "(stupid|spiders|-?)" GoAway=1
    Deny from env=GoAway
</LocationMatch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment