AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[rate-limiting](server)

Martin Hope
Elkrat
Asked: 2022-01-31 14:00:46 +0800 CST

使用 NGINX limit_req_zone 仅对主页进行速率限制

  • 0

我有一个 Wordpress 多站点安装,并且我有一些机器人正在敲击主页。我想仅在网站的主页上设置速率限制,但其他页面不受限制。

我的麻烦是制作一个与主页的“空白”地址匹配的 NGINX 位置 /index.php 我可以通过匹配“/”来限制整个站点,但这不是我需要的。

我尝试使用“索引”作为定义的位置,但这不起作用。有没有我错过的技巧?这是一个很难搜索的案例,因为大多数选择性限制问题来自做相反的人,人们限制具有更具体地址的资源,例如登录脚本。

这是我尝试过的:

limit_req_zone $binary_remote_addr zone=mainlimit:10m rate=1r/m;

server {

    # SSL configuration

    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    include snippets/ssl-example.com.conf;
    include snippets/ssl-params.conf;
    server_name example.com www.example.com;
    client_max_body_size 120M;

    root /usr/share/nginx/example;
    index index.php index.html index.htm;

    rewrite /wp-admin$ $scheme://$host$uri/ permanent;

    #subdomain multi site with wp in 'wp' subdir
    if (!-e $request_filename) {
    # Redirect wp-* files/folders
    rewrite ^(/[^/]+)?(/wp-.*) /wp/$2 last;

    # Redirect other php files
    rewrite ^(/[^/]+)?(/.*\.php) /wp/$2 last;
    }

    location index { #THIS DOES NOT MATCH THE HOME PAGE
        limit_req zone=mainlimit burst=3 nodelay;
        try_files $uri $uri/ /index.php?$args ;
    }

    location / {
        #limit_req zone=mainlimit burst=3 nodelay; THIS MATCHES EVERYTHING
        try_files $uri $uri/ /index.php?$args ;
    }
    location ~* /wp-content/uploads/.*\.php$ {
    return 503;
    }

    location ~* /data/.*\.php$ {
    return 503;
    }
 ***MORE STUFF...
rate-limiting nginx wordpress
  • 1 个回答
  • 367 Views
Martin Hope
Mnemosyne
Asked: 2021-12-30 00:43:52 +0800 CST

在 rsync 中,“bwlimit”参数被明确忽略,如何解决这个问题

  • 0

我在端口 873 上侦听了 rsyncd 版本 3.1.2,我想限制连接到我的客户端下载我的文件的带宽。我在配置文件中都添加了 bwlimit :

uid = nobody
gid = nogroup

[data]
path = /var/data/files/
comment = Repo
read only = yes
bwlimit = 10

并在守护进程配置文件上尝试过

[Unit]
Description=fast remote file copy program daemon
ConditionPathExists=/etc/rsyncd.conf

[Service]
ExecStart=/usr/bin/rsync --daemon --no-detach --bwlimit=10

[Install]
WantedBy=multi-user.target

在任何一种情况下,当我的客户端连接到 rsync 以下载文件时,每个日志都会忽略该参数:

Dec 29 08:27:12 pubserver systemd[1]: Started fast remote file copy program daemon.
Dec 29 08:27:12 pubserver rsyncd[32533]: rsyncd version 3.1.2 starting, listening on port 873
Dec 29 08:29:42 pubserver rsyncd[1534]: Unknown Parameter encountered: "bwlimit"
Dec 29 08:29:42 pubserver rsyncd[1534]: IGNORING unknown parameter "bwlimit"
Dec 29 08:29:42 pubserver rsyncd[1534]: connect from workspace (10.155.120.1)
Dec 29 08:29:42 pubserver rsyncd[1534]: rsync on repo/ from workspace (10.155.120.1)
Dec 29 08:29:42 pubserver rsyncd[1534]: building file list
Dec 29 08:29:44 pubserver rsyncd[1534]: sent 17567 bytes  received 72 bytes  total size 16787953

有没有办法使这个限制起作用?或者,如果不再支持 bwlimit,如何减慢/限制 rsync 连接?

ssh rsync rate-limiting throttling
  • 1 个回答
  • 142 Views
Martin Hope
realnsleo
Asked: 2021-09-09 21:50:06 +0800 CST

是否可以创建 AWS API 网关以将所有请求路由到 Classic Load Balancer?

  • 0

我有一个问题(希望不是愚蠢的)。我是一家使用 AWS 托管各种应用程序的企业的 IT 人员,我们目前有一个 Classic Load Balancer,位于 2 到 3 个处理我们所有 Web 流量的 EC2 实例前面。这是一个非常简单的配置。在过去 13 小时内,我们受到了我们认为是恶意活动的打击。一个人(我认为)试图每秒发送超过 500 个请求,我猜是个坏演员。不幸的是,我没有很好的 devops 技能,但我知道这是我需要在此之后投资的一个领域。

目前,我希望尽快阻止/速率限制这些请求。我在网上读到 API 网关可以做到这一点。我将不胜感激有关创建哪种类型的 API 网关的任何建议。是否也可以创建一个 API 网关并将所有到该网关的请求路由到负载均衡器?是否也可以根据请求主体而不是 IP 地址来限制请求?谢谢,我非常感谢对此的任何回应。我也很高兴在必要时改进我的问题。

load-balancing rate-limiting amazon-web-services amazon-api-gateway ip-blocking
  • 1 个回答
  • 120 Views
Martin Hope
Little Apocrypha
Asked: 2021-09-06 01:07:40 +0800 CST

将 nginx 限速 IP 记录到特定文件中

  • 1

我正在寻找一种在 nginx 节点之间同步限速 IP 的方法。我想记录这些 IP,然后将它们推送到数据库中并开发一个代理来更新 nginx 配置文件中被阻止的 IP。

我的挑战是找到一种方法让 IP nginx 限制429状态码。

那么,是否可以将限速 IP 记录到 nginx 中的特定文件中,或者您是否建议任何其他方法在节点之间同步限速 IP?

synchronization rate-limiting nginx
  • 1 个回答
  • 63 Views
Martin Hope
Rushy
Asked: 2021-08-30 07:40:38 +0800 CST

在通过 GRE 隧道发送之前,ipset 列表中 UDP 流量的速率限制 IP

  • 1

我正在使用 nat DNAT 通过 GRE 隧道将某个端口上的流量转发到另一个 Centos 服务器,但是我想对 ipset 列表“黑名单”中的一组数据中心 IP 进行速率限制。从而限制输出到隧道的流量。

我已经尝试在所有 FORWARD、INPUT 和 OUTPUT 列表中进行速率限制,但是速率限制在它们中的任何一个中都不起作用——也许 nat DNAT 绕过了它?

iptables -A INPUT -m set --match-set blacklist src -p udp --dport 30000 -m hashlimit --hashlimit 10/min --hashlimit-name ratelimithash -j DROP
iptables -A FORWARD -m set --match-set blacklist src -p udp --dport 30000 -m hashlimit --hashlimit 10/min --hashlimit-name ratelimithash -j DROP
iptables -A OUTPUT -m set --match-set blacklist src -p udp --dport 30000 -m hashlimit --hashlimit 10/min --hashlimit-name ratelimithash -j DROP

如果我通过 'iptables -A OUTPUT -m set --match-set blacklist src -j DROP' 添加要删除的列表,它会停止所有流量,所以我的 IP ipset 列表正在工作,只是没有速率限制,任何人都可以帮忙?

iptables 输出:

iptables 输出

iptables NAT 输出:

iptables nat 输出

iptables 规则


#!/bin/sh
iptables -F
sudo iptables -t nat -F
iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -t raw -F
sudo iptables -t raw -X
sudo iptables -t security -F
sudo iptables -t security -X
sudo iptables -F
sudo iptables -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT

iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT

iptables -A INPUT -m set --match-set blacklist src -p udp --dport 30000 -m hashlimit --hashlimit 10/min --hashlimit-name ratelimithash -j DROP
iptables -A FORWARD -m set --match-set blacklist src -p udp --dport 30000 -m hashlimit --hashlimit 10/min --hashlimit-name ratelimithash -j DROP
iptables -A OUTPUT -m set --match-set blacklist src -p udp --dport 30000 -m hashlimit --hashlimit 10/min --hashlimit-name ratelimithash -j DROP

iptables -t nat -A POSTROUTING -s 192.168.168.0/30 ! -o gre+ -j SNAT --to-source 20&&&&&&&&&&&&

iptables -A INPUT -s 192.168.168.2/32 -j ACCEPT

iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT


iptables -A INPUT -p gre -j ACCEPT
iptables -A OUTPUT -p gre -j ACCEPT

iptables -t nat -A PREROUTING -d 20&&&&&&&&&&&& -p udp --dport 30000 -j DNAT --to-destination 192.168.168.2


iptables -A OUTPUT -j DROP
iptables -P INPUT DROP

centos rate-limiting iptables ipset
  • 1 个回答
  • 68 Views
Martin Hope
sanjib
Asked: 2021-02-22 09:59:57 +0800 CST

后缀中的速率限制

  • 1

所以我一直在尝试制作一个运行良好的邮件服务器,现在我想要的是限制邮件用户可以发送的邮件数量得到任何回应认为如果你们中的任何人有解决方案

所以,基本上我想要实现的是我希望每个用户每 5 分钟限制 2 封电子邮件希望这清楚

所以关于我该如何处理的任何建议

我以前的政策问题的链接

linux centos postfix rate-limiting policyd
  • 1 个回答
  • 412 Views
Martin Hope
CodeFlo
Asked: 2020-11-29 04:28:47 +0800 CST

我可以在 Apache 中对 HTTP 基本身份验证使用速率限制吗?

  • 3

所以我在我的服务器上运行了一些流行的 Web 应用程序。我希望这些可以从任何计算机上访问,而不会造成太多漏洞。

我使用 Apache 2.4.29 作为我的 HTTP 服务器。我目前对攻击者隐藏应用程序中潜在安全漏洞的想法是AuthType Basic为相关虚拟主机启用 HTTP 基本身份验证 () 作为附加安全层。当然,我只允许 SSL 连接。

现在这一切都很容易完成。但我的问题是:我怎样才能最好地避免使用 HTTP 基本身份验证的蛮力式攻击?即,如何启用速率限制?

我目前的计划是这样的:

由于我使用 ufw(简单防火墙)来限制 SSH 连接,我想我可以在用于 HTTPS 的特定端口上做同样的事情。但是,我看到了两个问题:

  1. 攻击者不能在Connection: Keep-Alive不重新连接的情况下使用并继续尝试不同的密码吗?所以限制传入连接在这里没有任何用处。
  2. 如果我以某种方式禁用Connection: Keep-Alive,我想我会遇到底层 Web 应用程序的问题,因为它们需要大量单独的连接,以便浏览器可以检索其他文件。

如果我可以指示 Apache 只为经过身份验证的用户保持连接并在尝试失败时断开连接,那将是完美的。有没有办法做到这一点?我实际上不确定默认行为是什么,并且对 HTTP 了解不够,无法轻松测试。

Apache 中的KeepAliveandMaxKeepAliveRequests设置显然可以基于每个虚拟主机进行配置,但我不确定如何根据成功的身份验证更改这些设置。

security rate-limiting apache-2.4 ufw http-basic-authentication
  • 1 个回答
  • 746 Views
Martin Hope
Mario Mlinaric
Asked: 2020-10-05 00:27:13 +0800 CST

如何限制每个用户的 linux CPU 和 RAM 使用率

  • 3

我想限制每个用户的 CPU 和 ram 使用量。

所以,假设有用户 john。他可以运行任意数量的进程,但他还需要拥有 2048 兆字节的内存和 2 个 CPU 内核。

我知道有像'ulimit'和'nice'这样的方法,但我仅限于一个命令,所以我需要这样的东西:

limiter_cmd -ram 2048 -cpu 2 screen -s 1 ./script

另外,我正在使用“屏幕”命令来保存会话。

linux rate-limiting
  • 1 个回答
  • 5884 Views
Martin Hope
Finrod Felagund
Asked: 2020-07-14 12:54:14 +0800 CST

从 NGINX 速率限制中排除位置

  • 2

我在 nginx 的 http 块中定义了两者limit_req_zone,limit_req因此它将适用于所有服务器和位置块。

有没有办法从该限制中排除某个位置或服务器块?

nginx.conf:

http {
...
limit_req_zone $binary_remote_addr zone=main:10m rate=25r/s;
limit_req zone=main burst=100 nodelay;
limit_req_status 429;
...
}

myserver.conf:

server {
...
     location /web/ {
     directive_to_disable_ratelimit
     }
...
}

我能想到的唯一解决方法是为我要排除的位置或服务器设置一个非常高的爆发。因此,有效地永远不会达到极限。

rate-limiting nginx
  • 1 个回答
  • 1576 Views
Martin Hope
radonthetyrant
Asked: 2020-03-05 11:49:51 +0800 CST

被 HEAD 请求淹没

  • 3

我们的服务器被 HEAD 请求淹没了。

这导致 tcp 连接激增,导致服务器无法连接到其 mysql 数据库。

我们广泛使用了 nginx 速率限制,它与 fail2ban 完美结合,适用于任何 GET 和 POST 请求。但是,似乎没有收到 HEAD 请求。

我们使用的 fail2ban filter.d 操作nginx-limit-req似乎是一个股票配置,用于检测何时达到 nginx 区域限制。

由于我们的 webapp 不需要 HEAD 请求,我们有两个选择(除了手动禁止单个 IP 地址)

  1. 有没有办法禁用 HEAD 请求?这似乎是气馁,但它可能仍然吗?
  2. 是否可以让 nginx 区域限制器识别任何 GET/POST/HEAD 请求并相应地限制它?

nginx.conf:

http {
  ...
  limit_req_zone "$http_x_forwarded_for" zone=web_zone:50m rate=2r/s;
  ...
}

server {
  ...
  fastcgi_buffers 16 16k;
  fastcgi_buffer_size 32k;

  location / {
    limit_req zone=web_zone burst=25;
    try_files $uri $uri/ @pretty-urls;
  }
  ...
}

监狱.conf:

[nginx-limit-req]
enabled = true
filter = nginx-limit-req
action = custom-iptables-proxy
port = http,https
logpath = /var/log/nginx/*error*.log
findtime = 10
bantime = 3600
maxretry = 3

nginx-limit-req.conf:

[Definition]
ngx_limit_req_zones = [^"]+
failregex = ^\s*\[[a-z]+\] \d+#\d+: \*\d+ limiting requests, excess: [\d\.]+ by zone "(?:%(ngx_limit_req_zones)s)", client: <HOST>,
ignoreregex =
datepattern = {^LN-BEG}

访问日志中的示例: 在此处输入图像描述

事件期间的netdata,违规者ip被封禁后正常化:

在此处输入图像描述

rate-limiting nginx fail2ban
  • 1 个回答
  • 844 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve