Would you like to learn how to install Nginx and deny access to an IP address list? In this tutorial, we are going to configure the Nginx server to block the access from an IP address list.
• 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.
Nginx – Related Tutorial:
On this page, we offer quick access to a list of tutorials related to Nginx.
Tutorial Nginx – Blocking an IP address list
Install the Nginx server.
Edit the Nginx configuration file for the default website.
Add the following line to the configuration file.
Here is the file, before our configuration.
Here is the file, after our configuration.
Create a file containing the list of IP addresses.
Here is the file content.
Configure the file permission.
Restart the Nginx service.
In our example, the Nginx server will forbid access from IP addresses included on the file named BLACKLIST.
In our example, we blocked the entire network 192.168.1.0/24.
In our example, we blocked the IP address 192.168.2.102.
From a computer included on the list, try to access the Nginx server.
The Nginx server will deny access and display an error message.
The Nginx server will deny access based on the access list file named BLACKLIST.
Congratulations! You are able to deny access to the Nginx server based on the source IP address.