How to get the current hostname in VCL?


#1

If I use req.http.host in the src parameter of a header, I get the hostname of the backend.
How can I get the request hostname instead?

I’d like to not have to hardcode my domain.

Thanks!


#2

Hey @analogue, try req.backend.

req.http.host pulls the inbound request Host header, so getting the domain for that is to be expected.


#3

If you are trying to get information about the origin, this help guide my be useful as well - Tracking you origin’s name, ip, and port


#4

I don’t think my question was clear enough =)

If I serve domain.com with Fastly, I’d like to get “domain.com” somewhere.
Not the hostname of a backend.

I solved this by setting a new variable:
set req.http.original_host = req.http.host