Hi, Im wondering if I can set the host field of the “backend” structure during script execution - and if the value I set it to can come from a combination of a string + header values?
set req.http.enviroment = // some code to parse the environment from the hostname e.g., "staging"
set req.backend = Canonical_Backend;
set req.backend.host = req.http.environment “.” req.http.host “.backend”; // set backend’s “host” field dynamically based on headers and a string value
The reason I want to do this is because I have 10 backends in any one of 4 “environments”. The environments are staging, qa, production and dev. That is 40 backends to deal with. The VCL code for each and all of these environments is almost the same so I would like to write the code once (one vcl script) and use in all environments.
In my case, the backend can be determined based on the req.http.url and the “environment”. So for example, one backend could be “staging.cms.example.com” and another would be “qa.cms.example.com” and yet another is “production.admin.example.com” etc. Instead of hardcoding all 40 backends in my VCL I would just create 1 and then substitute the actual value for the “host” field on-the-fly at request processing time.