有什么方法可以确保在 Linux 中向某个站点发送的 HTTP 请求不超过 x 个?

Any way to ensure that no more than x HTTP requests are sent to a certain site in Linux?

我正在使用 Docker,基本图像是 alpine。我有一个将 HTTP GET 发送到某个站点的应用程序,但我有一个限制,在 50 个请求之后我必须为每个请求支付一些费用,我想避免这种情况。 我还将对应用程序代码施加某种硬停止,但我想知道是否有某种方法也可以从 Linux 执行此操作,以防万一。 有什么办法吗?

在 Linux 操作系统级别,可以通过以下 3 种方式阻止出站请求:

  1. iptables出站规则

iptables -A OUTPUT -o eth0 -p tcp --syn --dport 80 -m connlimit --connlimit-above 50 -j DROP

  1. Linux 交通管制员 (tc)

More information:

http://man7.org/linux/man-pages/man8/tc.8.html

https://netbeez.net/blog/how-to-use-the-linux-traffic-control/

  1. 应用程序代理(鱿鱼或墨鱼)

More information:

https://www.linuxhelp.com/how-to-limit-bandwidth-squid

https://github.com/mrkschan/cuttle