Get origin server as variable
I have several origin servers, and some conditions to select some. Now I’d need to know which origin server served my request, but cannot find VCL variable for this. Based on description req.backend seemed to be promising, but when I put this to response header then I see something like cluster_dir_chash_stockholm_bma, which seems to be similar to X-Served-By:cache-bma7029-BMA and is therefore useless. I’d need to get name of my origin server, something like “F_MyServer1” or IP of it.
-
To add to the advice, you can unset that variable in vcl_deliver with the following custom vcl:
``` sub vcl_deliver {
FASTLY deliver
if (!req.http.Fastly-FF) { unset resp.http.X-Backend-Name; }
return(deliver); } ```
You can also capture the variable in vcl_fetch as a request header and use in logging:
`` set req.http.X-Backend-Name = beresp.backend.name; ```
Here is the help guide with details around Tracking your origin's name, ip, and port.
-
Thanks, it worked finally also without custom VCL, just in headers section. I tried to put it to Response header, but this gave error (beresp not available), the trick was to put it to the Cache header, and it seems this goes to the Response also. It is not completely clear from the docs what is "Cache header" exactly.
Please sign in to leave a comment.
Comments
3 comments