Re: Different host headers - same cache?
Guillaume, On 10/24/16 11:32, Guillaume Quintard wrote: > Why isn't unsetting the host header (to let varnish use .host_header) > acceptable? Oh that's perfectly acceptable, I just didn't know it did that! Because the Host header that came from the frontend always trumped .host_header, I didn't even think about trying that. Will do right away. > But only a madman would take pleasure in this. Mwahahaha... ;) Bye Frederik -- Frederik Ramm ## eMail frede...@remote.org ## N49°00'09" E008°23'33" ___ varnish-misc mailing list varnish-misc@varnish-cache.org https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: Different host headers - same cache?
Hi, On 10/16/2016 10:30 PM, Frederik Ramm wrote: > I should be able to do this: > > if (bereq.backend == "somedirector") ... > vgc.c:2152:35: error: comparison with string literal results in > unspecified behavior [-Werror=address] Ok, I meanwhile found out two things: 1. bereq.backend will contain the actual backend selected by the director, not the director itself; 2. for some reason I cannot do a string equality check against bereq.backend like above, but I can do if (std.strstr(bereq.backend, "somebackend")) { ... } - which doesn't make me entirely happy since a strstr is certainly more expensive than a string equality check but at least that seems to work! Bye Frederik -- Frederik Ramm ## eMail frede...@remote.org ## N49°00'09" E008°23'33" ___ varnish-misc mailing list varnish-misc@varnish-cache.org https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: Different host headers - same cache?
Thomas, thank you, that gets me a bit further. I have one more question though: On 10/16/2016 12:55 AM, Thomas Lecomte wrote: > You will need to rewrite bereq.http.host in the vcl_backend_fetch > routine depending on the backend to which you are sending the request. So which backend the request is sent to, has been determined in vcl_recv, using "set req.backend_hint=somedirector". Now I'm trying to do what you say, and in vcl_backend_fetch set the bereq.http.host according to which backend has been selected. I wanted to be clever and tried: set bereq.http.host = bereq.backend.host_header; (assuming that by the time that vcl_backend_fetch is called, the director would already have selected a specific backend). But "Symbol not found: 'bereq.backend.host_header' (expected type STRING)" Then I thought ok, since the docs say about bereq.backend: "When used in string context, returns the name of the director or backend, respectively." I should be able to do this: if (bereq.backend == "somedirector") { set bereq.http.host = "somehost"; } elsif (bereq.backend == "otherdirector") { set bereq.http.host= "otherhost"; } But (VRT_r_bereq_backend(ctx) == "somedirector") ^ vgc.c:2152:35: error: comparison with string literal results in unspecified behavior [-Werror=address] How can I force the "string context" on the backend/director, so that I can use string comparison to find out which backend has been selected? Or how can I otherwise compare bereq.backend with something? I also tried to access the req.backend_hint but that seems to be write-only. If all else files I could maybe abuse some otherwise unused variable in the "req" object that I can set in vcl_recv (where I determine which backend I want) and then read in vcl_backend_fetch? I guess it's probably all dead simple and I just didn't find it. Bye Frederik -- Frederik Ramm ## eMail frede...@remote.org ## N49°00'09" E008°23'33" ___ varnish-misc mailing list varnish-misc@varnish-cache.org https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Different host headers - same cache?
Hi, new varnish user here with a configuration question. I have two backend servers in a round-robin director. Both require different host headers to be set, but both deliver the same content and I want there to be only one cache that mixes content from both machines. Question 1: I tried to force the host header in the backend definition like so: backend A { .host = "1.2.3.4"; .host_header = "server_a" ... } but this didn't work; the .host_header did affect the "probe" requests it made automatically, but actual content requests still bore the name of the varnish server itself. I had to do a "set req.http.Host=..." in vcl_recv to actually change the Host header used, but that defeats my purpose since I want the round robin director to decide which backend to use. Is it a bug or a feature that .host_header doesn't actually override the host header for content requests? I'm on varnish 5.0.0. Question 2: Do I need to do anything to ensure that requests going to backends A and B, with host headers "server_a" and "server_b", land in the same cache? I know this is a problem I could probably solve by reconfiguring my backend servers to listen to the same host name but this would trip up another, unrelated aspect of my setup so if it can be avoided I'd like to avoid it. Bye Frederik -- Frederik Ramm ## eMail frede...@remote.org ## N49°00'09" E008°23'33" ___ varnish-misc mailing list varnish-misc@varnish-cache.org https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc