Would you like to learn how to install Nginx and deny the USER-AGENT access? In this tutorial, we are going to configure the Nginx server to block access to your website based on the USER-AGENT value.

• Ubuntu 18
• Ubuntu 19
• Ubuntu 20
• Nginx 1.18.0

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Tutorial Nginx - Blocking a User-agent

Install the Nginx server.

Copy to Clipboard

Edit the Nginx configuration file for the default website.

Copy to Clipboard

Add the following line to the configuration file.

Copy to Clipboard

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Restart the Nginx service.

Copy to Clipboard

In our example, we configured the Nginx server to deny access from user agents containing the words WGET and CURL.

From a remote computer, try to access the Nginx server using the User-agent named CURL.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Congratulations! You are able to deny access to Nginx based on the value of the User-agent.