Page 1 of 1

Blocare ROBOTI cu NGINX [Anti DDOS]

Posted: Sat Feb 10, 2024 1:35 pm
by CryWolf

Step 2: Install and Configure Nginx
If you haven't already installed Nginx, you can install it using your operating system's package manager. Once Nginx is installed, you can proceed with the configuration.

Step 3: Create a List of Bad Bots
Create a list of bad bots that you want to block. You can find publicly available lists of known bad bots online or compile your own based on your website's traffic patterns and security requirements.

Step 4: Create a New Configuration File
Create a new configuration file in the Nginx configuration directory (usually located at /etc/nginx/conf.d/ or /etc/nginx/sites-available/) to define rules for blocking bad bots. You can name the file something like block-bad-bots.conf.

Step 5: Configure Nginx to Block Bad Bots
Open the block-bad-bots.conf file with a text editor and add the following Nginx configuration directives:


Code: Select all

map $http_user_agent $bad_bot {
    default 0;
    ~*(bot1|bot2|bot3) 1;  # Add the list of bad bots here

Code: Select all

server {
    if ($bad_bot) {
        return 403;
    # Add your regular server configuration here
In the above configuration:

The map directive defines a mapping between the HTTP user agent header and a variable called $bad_bot. If the user agent matches any of the specified bad bots, the variable $bad_bot is set to 1.
The server block contains an if statement that checks if the $bad_bot variable is set to 1. If it is, Nginx returns a 403 Forbidden response to the client.

Step 6: Test the Configuration
Before applying the configuration changes, test the Nginx configuration for syntax errors:


Code: Select all

sudo nginx -t
If the test is successful, reload Nginx to apply the changes:


Code: Select all

sudo systemctl reload nginx
Step 7: Monitor and Adjust
Monitor your server logs and website traffic to ensure that the bad bots are being blocked effectively. Periodically review and update your list of bad bots as needed.

That's it! You've successfully configured Nginx to block bad bots. This helps enhance the security and performance of your website by reducing unwanted traffic and potential security threats.