I want to block bad bots (any visitor with user agent below 14 symbols length). So I tried to modify default Nginx template for the site adding right at the top of .tpl and .stpl code before server line:
And inside server before the first location I put this:
if ($blocked) {
return 403;
}
I made a copy of the template, added it to my domain via panel and rebuild the user. But it doesn’t work :(. I can see 200 OK for visitors without User Agent or with short ones in logs.
Is it OK to use map like this in .tpl or should I put it into nginx.conf directly?
If you define map directive outside server block, the directive will be global so there is no need to add it to .stpl, indeed I won’t use it in a template, I would define it on for example /etc/nginx/conf.d/maps.conf
Also, you should surround the regex with double quotes or it will fail:
Thanks. Let me try that.
BTW, how would one run websites and servers without apache and nginx? I thought one cannot have public websites without these 2.
no no. Let me rephrase. I meant, one needs to have either apache or nginx to run, right? Apologies, if this question sounds naive or stupid, but I have seen many write, I do not use nginx, or I do not use apache, etc. So, I am in general confused. Hence this question.