如何在cloudflare worker中设置另一个主机标头?例如,我已经为我的站点的www记录设置了1.2.3.4 ip默认情况下,www请求是使用标题www.ex.com发送的,但我想发送带有new.ex.com标题的www请求
发布于 2020-01-01 11:49:04
您需要为new.ex.com
配置DNS记录,使其指向相同的IP地址。然后,您可以在URL中使用new.ex.com
发出fetch()
请求。
如果您无法使new.ex.com
指向正确的IP,另一种方法是使用resolveOverride
选项发出fetch()
请求,以指定要使用的不同主机名的IP地址:
fetch("https://new.ex.com", {cf: {resolveOverride: "www.ex.com"}});
请注意,只有当涉及的两个主机名都在您的区域中时,这才有效。Documentation about resolveOverride
can be found here.
您不能直接设置Cloudflare标头,因为这样做可能会在向也使用Host
的第三方服务器发出请求时允许绕过安全设置。
发布于 2020-05-16 05:10:24
// Parse the URL.
let url = new URL(request.url)
// Change the hostname.
url.hostname = "check-server.example.com"
// Construct a new request
request = new Request(url, request)
请注意,这将影响源服务器看到的主机标头(它将是check-server.example.com)。有时人们希望Host报头保持不变。
// Tell Cloudflare to connect to `check-server.example.com`
// instead of the hostname specified in the URL.
request = new Request(request,
{cf: {resolveOverride: "check-server.example.com"}})
https://stackoverflow.com/questions/59527354
复制相似问题