First of all, let's see in large lines what this user-agent of an Internet browser is and what it uses.
content
What is user agent (or user-agent)?
All the Internet Browser means (Internet Explorer, Safari, Opera, Firefoc, Chrome, etc.) have an agent software that interacts with the website you visit, at the host server level. This software makes the Internet connection with the website, understands, checks and will restore the content of the accessed page. In short, it ensures the interaction between the user and the host server that serves the user the requested web pages by accessing a specific URL on the HTTP / https protocol.
User Agent contains in the header delivered to the server it accesses, information about the software used by the user, the operating system, the version of the Browser software package. For example, the user-agent for Google Chrome will play the server information about the Google Chrome version and the user's operating system.
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3163.100 Safari/537.36
The User-Agent Header above means that a version of Google Chrome 70 on a computer with procesor AMD, 64-biti architecture with operating system Windows 10.
You will probably ask yourself Why Mozilla appears as a user-agent for Chrome. This is a kind of trick used by Google (and Microsoft in IE) to facilitate the access of Chrome users on all sites compatible with Mozilla and Safari. AppleWebKit is the content play engine.
Webmasters or web server administrators can block the access of certain users of agents at the webistees hosted. Most of the time this limitation is put web robots (web bots) that access chaotic or excessively the web pages of a website. Fortunately, these bots have a specific user-agent and can be easily detected in web servers logs.
How we block an access to a user-agent on a web server with NGINX
Let's take the scenario in which we no longer want to allow this website to users with Windows XP operating systems and Internet Mozilla Firefox 5.0.
We add the code below the file is configuration nginx, at “server” block:
if ($http_user_agent = "Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101 Firefox/52.0"){
return 403;
}
Save the file ningx.conf or the specific file of a website, if you use personalized configuration (genus-available), then Restart the NGINX service.
All users with Firefox 5.0 (including all versions up to 5.9) on Windows XP, will be redirected to error 403 (Forbidden).
I did not accidentally choose this example. Starting with Firefox 52.9.0, Mozilla has stopped support for Windows XP and Windows Vista users. Operating systems whose support was also stopped by Microsoft in 2014, respectively 2017 for Windows Vista.