Varnish url redirection does not work
Brad Tarver
idle at pobox.com
Sat Feb 27 00:15:54 CET 2016
Just yesterday I needed to do this. I host a friend's personal blog.
Originally I had a line in my default.vcl that sent any queries for
example.org/.info/.net to the nginx backend on the same machine.
However, I like yours better. It is simpler in execution than mine.
Old:
vcl_recv {
if (req.http.host == "(www.)example.\borg|info|net\b" ) {
set req.backend_hint = default;
}
}
This is a wordpress site mind you. He noticed this issue yesterday and
sent me a text. He updated his site @ example.org/wordpress/wp-admin/.
Someone he works with asked about his blog and he replied with
"example.net." Well, when his coworker when to example.net, my friend's
new post wasn't there. Surf to example.org and there sits the new post.
So, this tells me that varnish is keeping a separate cache for each
domain.tld of my friend's blog even though it's derived from the same WP
install.
New:
vcl_recv {
if (req.http.host == "(www.)example.org") {
set req.backend_hint = default;
}
if ( (req.http.host ~ "^(?i)www.example.net" || req.http.host ~
"^(?i)example.net" || req.http.host ~ "^(?i)www.example.info" ||
req.http.host ~ "^(?i)example.info") ) {
return (synth(750, ""));
}
}
sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = "http://www.example.org" + req.url;
return(deliver);
}
}
I tested using curl -I and chrome and both worked wonderfully.
I'm going to try out your example and see what I get. Thank you
--
Sent from Postbox
<https://www.postbox-inc.com/?utm_source=email&utm_medium=siglink&utm_campaign=reach>
Paul A. Procacci wrote:
> On Fri, Feb 26, 2016 at 12:01:57PM +0200, georgi.int at gmail.com wrote:
>> Hello,
>> I would like to ask your for help after explaining the case and the
>> infrastructure for this domain. In the varnish configuration I restrict
>> some types of files to be accessed and downloaded and if some customer
>> wants to use this functionality I configure subdomain on it's domain on
>> nginx where these restrictions are not present. Although, my customer
>> do not want to change the links to the new subdomains (which rely on
>> nginx) in it's application and I want to redirect all old urls
>> (domain.com/somedir/download) to the new one - download.thedomain.com,
>> so if someone open the old url it's redirected to the subdomain on
>> nginx and the content to be loaded from nginx, not varnish (as the way
>> cpanel domain forwarder works).
>> The problem is that when I followed and configured the varnish official
>> documentation url guide it just change the url in varnishlog, but the
>> content is again openef from varnish, not nginx, also the url in the
>> browser is not rewritten.
>> My questions are 1) is it possible and if yes how, but if not 2) what
>> workaround can I use?
>> Thank you in advance. I will wait for you reply.
>
> Hello,
>
> It'd be helpful if you shared the parts of your configuration which perform
> the rewriting of the url.
>
> That aside, in order for the browser to request a differnet resource requires
> a 301 (or similar) to be delivered from varnish or nginx. Here's an example:
>
> #####################################################
> sub vcl_recv
> {
> if(req.http.host ~ "(?i)^nothere\.com$"){
> if(req.url ~ "(i?)^/file\.jpg$") {
> return(synth(750, "http://here.com" + req.url));
> }
> }
> }
>
> sub vcl_synth
> {
> if(resp.status == 750){
> set resp.http.Location = resp.reason;
> set resp.status = 301;
> return (deliver);
> }
> }
> #####################################################
>
> Hope this helps.
>
> ~Paul
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20160226/9317ecd7/attachment.html>
More information about the varnish-misc
mailing list