Mailing List Archive

htaccess redirects not working after a while
Hi,

  I have the following setup:

  Apache SSL (proxy) ->  Varnish -> Apache non SSL (Wordpress backend)

  I have in place several redirects in htaccess so if someone wants to
reach the non-SSL site, is redirected to SSL:

  http://www.mydomain.com -> https://www.mydomain.com

  http://mydomain.com -> https://www.mydomain.com

  I do this with the following:

  RewriteCond %{HTTP_HOST} !^www.mydomain.com$ [NC]
  RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,R=301]

  However I realized that from time to time redirects stop working and I
have to purge the Varnish cache and then the redirects work again.

  Why is that?

  Regards,

  Miguel

 



---
This email has been checked for viruses by AVG.
https://www.avg.com

_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: htaccess redirects not working after a while [ In reply to ]
> However I realized that from time to time redirects stop working and I
> have to purge the Varnish cache and then the redirects work again.

Can you share the code in your vcl_hash() function? My immediate guess would be that it's not taking into account the protocol of the request (http vs. https) and giving you wrong cache hits as a result.

Mattias

_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: htaccess redirects not working after a while [ In reply to ]
Here you have it:
# The data on which the hashing will take placesub vcl_hash {        hash_data(req.url);        if (req.http.host) {        hash_data(req.http.host);        } else {        hash_data(server.ip);        }        # If the client supports compression, keep that in a different cache        if (req.http.Accept-Encoding) {                hash_data(req.http.Accept-Encoding);        }        return (lookup);}


>> However I realized that from time to time redirects stop working and I
>> have to purge the Varnish cache and then the redirects work again.

>Can you share the code in your vcl_hash() function? My immediate guess would be that it's not taking into >account the protocol of the request (http vs. https) and giving you wrong cache hits as a result.

>Mattias
Re: htaccess redirects not working after a while [ In reply to ]
> Here you have it:

You are not caching the protocol (http or https), which will lead to different caching results depending on the backend response.

As an example, have a look here: https://github.com/mattiasgeniar/varnish-6.0-configuration-templates/blob/master/default.vcl#L236-L238

In your Apache proxy config you can set additional headers to mark they've been passed through it (in this example, X-Forwarded-Proto) so Varnish knows to treat them differently.

Mattias

_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: htaccess redirects not working after a while [ In reply to ]
I use Varnish 4.1, can I just add in the vcl_hash this?

| # Cache the HTTP vs HTTPs separately |
| | if (req.http.X-Forwarded-Proto) { |
| | hash_data(req.http.X-Forwarded-Proto); |
| | } |

 




En jueves, 13 de diciembre de 2018 10:05:20 CET, Mattias Geniar <mattias@nucleus.be> escribió:

> Here you have it:

You are not caching the protocol (http or https), which will lead to different caching results depending on the backend response.

As an example, have a look here: https://github.com/mattiasgeniar/varnish-6.0-configuration-templates/blob/master/default.vcl#L236-L238

In your Apache proxy config you can set additional headers to mark they've been passed through it (in this example, X-Forwarded-Proto) so Varnish knows to treat them differently.

Mattias
Re: htaccess redirects not working after a while [ In reply to ]
Hi,

You can. Alternatively, if the SSL terminator is sending traffic to varnish
via another port, you can unconditionally hash the listening port:

hash_data(std.port(server.ip));

(don't forget to import std first)
--
Guillaume Quintard


On Thu, Dec 13, 2018 at 10:16 AM Miguel Gonzalez <miguel_3_gonzalez@yahoo.es>
wrote:

> I use Varnish 4.1, can I just add in the vcl_hash this?
>
> # Cache the HTTP vs HTTPs separately
> if (req.http.X-Forwarded-Proto) {
> hash_data(req.http.X-Forwarded-Proto);
> }
>
>
>
>
> En jueves, 13 de diciembre de 2018 10:05:20 CET, Mattias Geniar <
> mattias@nucleus.be> escribió:
>
>
> > Here you have it:
>
> You are not caching the protocol (http or https), which will lead to
> different caching results depending on the backend response.
>
> As an example, have a look here: https://github.com/mattiasgeniar/varnish-6.0-configuration-templates/blob/master/default.vcl#L236-L238
>
>
> In your Apache proxy config you can set additional headers to mark they've
> been passed through it (in this example, X-Forwarded-Proto) so Varnish
> knows to treat them differently.
>
>
> Mattias
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc@varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>