21
# Flag the bots or conditions you want to block without logging
map $http_user_agent $blocked_bot {
default 0;
~*badbot 1; # Example bot pattern
}
server {
listen 80;
# Main access log - requests blocked without logging won't appear here
access_log /var/log/nginx/access.log combined;
# Dummy log for blocked requests, you can ignore this file
# Alternatively, you can set it to /dev/null if you don't want to keep these logs at all
access_log /var/log/nginx/blocked.log combined if=$log_blocked;
# Regular location blocks and server configuration go here
if ($blocked_bot) {
set $log_blocked 0; # Do not log
rewrite ^ /blocked_bot last; # Redirect to a named location for handling
}
# Named location for handling blocked requests without logging
location @blocked_bot {
access_log off; # Disable logging for this location
return 403;
}
}
curl -k -u "username" https://ddnbgroup.com/wp-json/wp/v2/types/post?context=edit
{"code":"rest_forbidden_context","message":"Sorry, you are not allowed to edit posts in this post type.","data":{"status":401}}
curl -k -u "username" https://ddnbgroup.com/wp-json/wp/v2/types/post?context=view
{
"description": "",
"hierarchical": false,
"has_archive": false,
"name": "Posts",
"slug": "post",
"icon": "dashicons-admin-post",
"taxonomies": [
"category",
"post_tag"
],
"rest_base": "posts",
"rest_namespace": "wp/v2",
"_links": {
"collection": [
{
"href": "https://ddnbgroup.com/wp-json/wp/v2/types"
}
],
"wp:items": [
{
"href": "https://ddnbgroup.com/wp-json/wp/v2/posts"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}