What is it and how we block the access of a User Agent (Bot or Browser) on a website [NGINX Tips]

First of all, let's see in broad terms what this user-agent of an Internet browser is and what he uses.

What is User Agent (or User-Agent)?

All that means internet browser (Internet Explorer, Safari, Opera, Firefox, 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 display the content of the accessed page. In short, it ensures the interaction between the user and the host server that serves the user the web pages requested by accessing a specific URL on the HTTP protocol / HTTPS.
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 software package of the browser. For example, the Google Chrome user-agent will provide the server with information about the version of Google Chrome used 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 header user-agent above means that a version of Google Chrome 70 on a computer with AMD processor, 64-bit architecture OS Windows 10.
You will probably wonder why Mozilla is appearing as a Chrome user-agent. This is a kind of trick used by Google (and by Microsoft in IE) to facilitate the access of Chrome users to all sites compatible with Mozilla and Safari. AppleW is the content playback engine.

Webmasters or administratorii web servers can block the access of certain user agents on webhosts hosted. Most of the time, this limitation is set web robots (web bots) that chaotic or excessive access to the web pages of a website. Fortunately, these bots have a specific user-agent and can be easily detected in web server logs.

How to block user-agent access on a web server with NGINX

Let's take the scenario where we no longer want to allow users to access the website with operating systems Windows XP and Mozilla Firefox 5.0 internet browser.

We add the code below the nginx configuration file, to the "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 nginx.conf or the file specific to a website, if you use custom configuration (gen sites-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 didn't randomly choose this example. Starting with Firefox 52.9.0, Mozilla has stopped support for users Windows XP yes Windows Vista. Operating systems whose support was stopped by Microsoft in 2014, respectively 2017 for Windows Vista.

Passionate about technology, I enjoy writing on StealthSettings.com since 2006. I have a rich experience in operating systems: macOS, Windows, and Linux, as well as in programming languages and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, PrestaShop).

How to » Internet » Internet Explorer » What is it and how we block the access of a User Agent (Bot or Browser) on a website [NGINX Tips]
Leave a Comment