我在一台有三个IPv4地址的VPS (Ubuntu19.x)上使用fastify和fastify-http-proxy。我可以使用(示例IP)验证它们的功能:
curl --interface 45.63.23.63 api.ipify.org
curl --interface 45.63.72.48 api.ipify.org
curl --interface 45.63.40.39 api.ipify.org我看到here可以通过向节点的http请求提供localAddress来提供接口。有没有人用fastify或fastify-http-proxy这样做过?我搜索了这两个包,但在每个包中都找不到对它的支持。
我运行了一个将流量转发到主机的API。最近,它收到了大量(合法)流量,主机(索尼)的DDoS预防标记并阻止了它,因为来自单个地址的高流量。当联系到他们时,他们声称不能删除阻止,但我可以自由地更改我的VPS的IP。为了防止将来发生这种情况,我想将它使用的接口随机化。
谢谢!
发布于 2020-07-17 15:15:49
您可以通过以下设置来完成此操作:
server.register(require('fastify-http-proxy'), {
upstream: 'http://my-api.example.com',
prefix: '/api',
http: {
requestOptions: {
localAddress: '45.63.72.48'
}
}
})这样,您的所有请求都将拥有该IP。所有的请求选项都支持使用this settings,因为fastify-reply-from是在幕后使用的。
但是您有3个ips可用,所以您需要为每个不同的路由注册3次插件,或者构建一个像这样的"round getter“也应该可以工作:
const ips = [
'45.63.23.63',
'45.63.72.48',
'45.63.40.39'
]
let endlessIterator = ips[Symbol.iterator]()
const roundIps = {
get localAddress () {
let v = endlessIterator.next().value
if (!v) {
endlessIterator = ips[Symbol.iterator]()
v = endlessIterator.next().value
}
return v
}
}
server.register(require('fastify-http-proxy'), {
upstream: 'http://my-api.example.com',
prefix: '/api',
http: {
requestOptions: roundIps
}
})https://stackoverflow.com/questions/62941677
复制相似问题