Express 速率限制器无法与集群负载均衡器节点 js 一起使用

问题描述 投票:0回答:1

我尝试使用以下快速速率限制器:

require('express-rate-limit')({
    windowMs: 24 * 60 * 60 * 1000, // 24 hrs in milliseconds
    max: 5,
    message: 'You have exceeded the 5 requests in 24 hrs limit!',
    standardHeaders: true,
    legacyHeaders: false,
})

它工作正常,但是当我像这样应用集群负载均衡器时

if (cluster.isMaster) for (let i = 0; i < numCpus; i++) cluster.fork()
else shutdown(app.listen(PORT), mongoose)

它工作正常,除非请求在任何随机时刻由不同的进程处理。

它只是没有按预期工作。它不会阻止基于 IP 的请求。请帮助我或给我不同的速率限制器解决方案谢谢

node.js express load-balancing rate-limiting express-rate-limit
1个回答
0
投票

您应该使用 cluster-memory-store 来同步各个工作人员之间的点击。

或者,任何外部 store,例如 mongodb store,也可以使用。

© www.soinside.com 2019 - 2024. All rights reserved.