nexcess / magento-turpentine

A Varnish extension for Magento.
GNU General Public License v2.0
520 stars 252 forks source link

Redirect Issues after update #1171

Closed gewaechshaus closed 8 years ago

gewaechshaus commented 8 years ago

Hey there,

after updating turpentine to 0.6.9 I noticed that some of our redirects aren't working anymore. Does anybody did notice issues related to that? We're using a self-compiled varnish 3 version.

custom.vcl, stripped down

 sub vcl_recv {
       ...
       set req.http.X-Country-Code = geoip.country_code(""+client.ip);     
       ...
       if (req.http.cookie ~ "geoipbypass=at" || req.http.User-Agent ~ "Payment Network AG") {
           set req.http.X-2D2 = 1;
       }

      ################################################
      # GeoIP redirect
      ################################################
       if(req.http.X-Country-Code == "DE" && !(req.http.X-2D2)){
            if(req.http.host == "www.xxx.at"){
                error 750 "http://www.xxx.de"; 
              }   
        }elseif(req.http.X-Country-Code == "AT"){
            if(req.http.host == "www.xxx.de"){
               error 750 "http://www.xxx.at"; 
              }   
        } 
 }

sub vcl_error {
  if (obj.status == 750) {
      set obj.http.Location = obj.response;
      set obj.status = 302;
      return(deliver);
   }
 }

sub vcl_deliver {
    set resp.http.X-TC =  geoip.country_code(""+client.ip);
    set resp.http.X-TCX = req.http.host;
  }

X-TC and X-TCX are returning the correct values to match the condition... "DE" "www.xxx.at"

https://www.varnish-cache.org/trac/wiki/VCLExampleRedirectInVCL

Best regards Jan

gewaechshaus commented 8 years ago

Tracked down to... Seems like the obj.status isn't set or vcl_error isn't getting triggered.

sub vcl_recv {
  if(req.http.host == "www.xxx.at"){
      error 750 "http://www.xxx.de"; 
  } 
} 
sub vcl_error {
   if (obj.status == 750) {
    set obj.http.Location = obj.response;
    set obj.status = 301;
    return(deliver);
  }
}
aricwatson commented 8 years ago

Thanks for following up with what you found!

gewaechshaus commented 8 years ago

Still didn't find a fix...

Even a error 750 "http://www.xxx.de"; hardcoded in vcl_recv without any conditions doesn't work anymore. vcl_error never gets triggered.

Can u try to reproduce this @aricwatson?

Please re-open. THX

gewaechshaus commented 8 years ago

Damn, this issue is mind-blowing simple but far reaching and a time expensive trip to the moon in the end... One had to write "start with the simplest, start with simplest, start with simplest when debugging" on the board. A programmers nature looks slightly different :).

It looks like all custom overwrites from custom.vcl aren't working anymore cause of the changed structure...

@aricwatson We've verified this the following way: Put a file called farnish.php (yeah f*ck varnish ;) :). it's a secret affair) in the magento root directory including the following code

 <?php 
 var_dump(microtime());

Add

if (req.url ~ "^/farnish\.php$") {
    return(pass);
 } 

in your custom.vcls vcl_recv. File is getting cached in our case...

Next step we went ahead with adding

 if (req.url ~ "^/farnish\.php$") {
   error 750 "http://www.xxx.at"; 
 } 

in default.vcl vcl_recv before

 if (req.restarts == 0) {

and just reload varnishd. TaDaa - redirects working. That also assumes that the overwrites only (logical) aren't working, cause the custom sub vcl_error routines are triggered. So i shouldn't be related to parsing stopping at point x.

gewaechshaus commented 8 years ago

@aricwatson - did u find the time to have a look at it?

aricwatson commented 8 years ago

@gewaechshaus Sorry been quite busy - FWIW we did run into a similar problem recently and found it was related to using the Normalize Host configuration option in Turpentine. Turning that to off fixed some htaccess based redirect issues that we were having.

Since you're (trying) to do this in the VCL - I wonder if the problem you're running into is that your custom VCL code is getting overridden. Can you try https://github.com/nexcess/magento-turpentine/pull/1212 to see if it'll give you better control over your generated VCL?

gewaechshaus commented 8 years ago

@aricwatson - No problem... Like Bob Marley said, every day is work ;) We did turn off normalization as we ran into serious session troubles in our multistore setup. Currently we're running a custom vcl, but #1212 looks more tidy than our dirty approach. Thx a lot, i'll post some feedback asap.