如何将 Nginx 服务器块中的 IP 地址/域列入黑名单

发布于 2025-01-09 01:21:25 字数 1492 浏览 0 评论 0原文

我正在尝试将一些正在访问我的网站的机器人列入黑名单。该机器人来自 paymentverificatiion.com <<请注意“验证”上的两个“i”。我首先通过执行 nslookup paymentverificatiion.com 找到了 IP 地址,该命令返回:

Non-authoritative answer:
Name:   paymentverificatiion.com
Address: 143.198.76.27

然后我尝试在每个位置块中放置 deny 语句,但这不起作用。然后我尝试将其放入服务器块中,但这不起作用:

upstream backend_server {
    server backend:8000;
}

server {
    listen 80;
    deny 143.198.76.27;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location /api/ {
        return 301 https://$host$request_uri;
    }

    location /admin/ {
        return 301 https://$host$request_uri;
    }
    
    location /static/ {      
        return 301 https://$host$request_uri;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.com *.example.com;

    location /api/ {
        proxy_pass http://backend_server$request_uri;
        ...omitted...
    }

    location /videos/ {
        ...omitted...
    }

    location /admin/ {
        proxy_pass http://backend_server$request_uri;
        ...omitted...
    }

    location /static/ {      
        alias /backend/assets/;
    }

    location /media/ {      
        alias /backend/media/;
    }

    location / {
        proxy_pass http://backend_server$request_uri;
        ...omitted...
    }
}

如何将这些机器人列入黑名单?

I am trying to blacklist some bots that are hitting one of my sites. The bot comes from paymentverificatiion.com << notice two "i"s on "verification". I first found the IP address by doing nslookup paymentverificatiion.com which returns:

Non-authoritative answer:
Name:   paymentverificatiion.com
Address: 143.198.76.27

I then tried putting a deny statement in each location block, but that did not work. I then tried putting it in the server block, but that does not work:

upstream backend_server {
    server backend:8000;
}

server {
    listen 80;
    deny 143.198.76.27;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location /api/ {
        return 301 https://$host$request_uri;
    }

    location /admin/ {
        return 301 https://$host$request_uri;
    }
    
    location /static/ {      
        return 301 https://$host$request_uri;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.com *.example.com;

    location /api/ {
        proxy_pass http://backend_server$request_uri;
        ...omitted...
    }

    location /videos/ {
        ...omitted...
    }

    location /admin/ {
        proxy_pass http://backend_server$request_uri;
        ...omitted...
    }

    location /static/ {      
        alias /backend/assets/;
    }

    location /media/ {      
        alias /backend/media/;
    }

    location / {
        proxy_pass http://backend_server$request_uri;
        ...omitted...
    }
}

How can I blacklist these bots?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文