Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cloudflare worker rewrite Host Header

How do I set up another Host Header in the cloudflare worker? For example, I have set up a 1.2.3.4 ip for my site's www record By default www requests are sent with the header www.ex.com but I want to send the www requests with the new.ex.com header

like image 794
javad Avatar asked Dec 09 '25 01:12

javad


1 Answers

You need to configure a DNS record for new.ex.com so that it points to the same IP address. Then, you can make a fetch() request with new.ex.com in the URL.

If you cannot make new.ex.com point at the right IP, another alternative is to make a fetch() request using the resolveOverride option to specify a different hostname's IP address to use:

fetch("https://new.ex.com", {cf: {resolveOverride: "www.ex.com"}});

Note that this only works if both hostnames involved are under your zone. Documentation about resolveOverride can be found here.

You cannot directly set the Host header because doing so could allow bypassing of security settings when making requests to third-party servers that also use Cloudflare.

like image 55
Kenton Varda Avatar answered Dec 12 '25 11:12

Kenton Varda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!