Nginx prohibits the method of specifying UA access_nginx blocks the specified user_agent

Nginx prohibits the method of specifying UA access. Friends in need can refer to:
1. Find the corresponding UA information
/robots.txt HTTP/1.1″ 200 24 “-” “Mozilla/5.0 (compatible; MJ12bot/v1.4.8;”

2. Add rules to our corresponding nginx file:
if ($http_user_agent ~* (Python-urllib|MJ12bot|Trident)) {
return 400;
Since there are some other things on the website, there are two more UA header information in the above rules

3. After the rules are added, save and restart the nginx service
nginx -t //for verification rules
service nginx retsrat //restart service
At this time, if we check the log again, we will find that the status code returned directly is 400 that we have set.

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.