Nginx Bot Map Generator (map $http_user_agent)

Creates the map and the server snippet that block or limit bots by user-agent.

Use the tool

Why this tool exists

The cleanest way to block bots in Nginx is a map on $http_user_agent that sets a variable, followed by one check in the server. It scales to long bot lists without chains of if statements.

List the tokens and choose block with a status code or rate limit with limit_req. The rate-limit variant uses an empty key for normal visitors so only flagged bots are limited.

How to use it

  1. List bot tokens.
  2. Choose block or rate limit and the variable name.
  3. Put the map in http {} and the rest in server {}.
  4. Reload Nginx and test with curl -A.

Frequently asked questions

Where does the map go?

In the http block, not inside server.

Why use map instead of if?

map is evaluated once, and if inside server has well-known pitfalls.

How does the rate limit skip normal visitors?

Their key is an empty string, which limit_req does not count.

Can I use 444?

Yes, set the status code option.