Get origin server as variable

Comments

3 comments

  • markwainwright

    I remember running into the same issue a while ago. I ended up putting the following in vcl_fetch:

    set beresp.http.X-Backend-Name = beresp.backend.name;

    This will automatically become a response header visible to the client.

    0
    Comment actions Permalink
  • Cassandra Dixon

    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.

    0
    Comment actions Permalink
  • jaakla

    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.

    0
    Comment actions Permalink

Please sign in to leave a comment.