Block particular user agent (bots) in nginx

From DevOps Notebook

Add inside nginx server block

    # case insensitive matching
    if ($http_user_agent ~* (crawler1|spiderbot|wget|curl)) {
        return 403;
    }