Nginx how to block acces to all server sites by connect headers?
While you can use the deny directive in an http block, it’s mostly useful for IP addresses and CIDRs, there’s no deny if directive with a variable check unfortunately. Your if block must be inside a location or server block, hence the emerg error.
You can create a separate file, called includes/block-ua.conf for example and drop the if/return block there, and include it from each server block in your configuration:
# includes/block-ua.conf
if ($http_user_agent ~* "censys") {
return 403;
}
Your sites configurations:
server {
server_name foo.org;
include includes/block-ua.conf;
}
server {
server_name bar.org;
include includes/block-ua.conf;
}
That helps maintain the user-agent block list in one place.
Read more here: Source link
