I use http://badbots.vps.tips/getcode which gives code for both NGINX and Apache.

An example vhost file:

upstream blog_upstream {
    server 10.120.155.245:80;
    keepalive 64;
}

server {
    listen 80;
    server_name blog.org;
    client_max_body_size 10M;
    if ( $http_user_agent ~* (AhrefsBot|AITCSRobot|Alexibot|Arachnophilia|archive\.org\_bot|ASpider|BackDoorBot|Baiduspider|BSpider|CFNetwork|CyberPatrol|DeuSu|DotBot|EmailCollector|Exabot|FeedlyBot|Genieo|Gluten\ Free\ Crawler|GrapeshotCrawler|MaxPointCrawler|meanpathbot$
        return 403;
    }

    location / {
        proxy_redirect off;
        proxy_set_header   X-Real-IP            $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host                   $http_host;
        proxy_set_header   X-NginX-Proxy    true;
        proxy_set_header   Connection "";
        proxy_http_version 1.1;
        proxy_pass         http://blog_upstream;
    }
}