Following redirects internally with Varnish -


i'm trying implement rubygems reverse proxy using varnish 4.1. clients inside intranet not have general outbound nat, need varnish internally follow redirects, preferably caching both 302 rubygems.org , response cdn server.

here's default.vcl:

vcl 4.0;  import std;  backend default {     .host = "rubygems.org";     .port = "80"; }  sub vcl_recv {     std.syslog(180, "doing vcl_recv");     std.syslog(180, "req.url = " + req.url); }  sub vcl_deliver {     std.syslog(180, "doing vcl_deliver");     std.syslog(180, "resp.status = " + resp.status);     if (resp.status == 302) {         set req.url = resp.http.location;         std.syslog(180, "restarting req.url = " + req.url);         return(restart);     } }  sub vcl_backend_fetch {     std.syslog(180, "doing vcl_backend_fetch");     std.syslog(180, "bereq.retries = " + bereq.retries); }  sub vcl_backend_error {     std.syslog(180, "doing vcl_backend_error"); } 

if curl -i http://localhost/latest_specs.4.8.gz, varnish throws http 503 , logs following:

varnishd[20384]: doing vcl_recv varnishd[20384]: req.url = /latest_specs.4.8.gz varnishd[20384]: doing vcl_backend_fetch varnishd[20384]: bereq.retries = 0 varnishd[20384]: doing vcl_deliver varnishd[20384]: resp.status = 302 varnishd[20384]: restarting req.url = http://rubygems.global.ssl.fastly.net/latest_specs.4.8.gz varnishd[20384]: doing vcl_recv varnishd[20384]: req.url = http://rubygems.global.ssl.fastly.net/latest_specs.4.8.gz varnishd[20384]: doing vcl_backend_fetch varnishd[20384]: bereq.retries = 0 varnishd[20384]: doing vcl_deliver varnishd[20384]: resp.status = 302 varnishd[20384]: restarting req.url = http://rubygems.global.ssl.fastly.net/latest_specs.4.8.gz varnishd[20384]: doing vcl_recv varnishd[20384]: req.url = http://rubygems.global.ssl.fastly.net/latest_specs.4.8.gz varnishd[20384]: doing vcl_backend_fetch varnishd[20384]: bereq.retries = 0 varnishd[20384]: doing vcl_deliver varnishd[20384]: resp.status = 302 varnishd[20384]: restarting req.url = http://rubygems.global.ssl.fastly.net/latest_specs.4.8.gz varnishd[20384]: doing vcl_recv varnishd[20384]: req.url = http://rubygems.global.ssl.fastly.net/latest_specs.4.8.gz varnishd[20384]: doing vcl_backend_fetch varnishd[20384]: bereq.retries = 0 varnishd[20384]: doing vcl_deliver varnishd[20384]: resp.status = 302 varnishd[20384]: restarting req.url = http://rubygems.global.ssl.fastly.net/latest_specs.4.8.gz 

it not seem requesting new url after updating req.url , restarting request.

this not definitive answer here thoughts:

1) "req.url" holds path part of url not contain protocol , host part of url. seems plain wrong me when assign "http://rubygems.global.ssl.fastly.net/latest_specs.4.8.gz" "req.url" in vcl_deliver , restart.

in opinion restarted request not hit "rubygems.global.ssl.fastly.net" still "rubygems.org" - defined default backend.

so guess need define second backend "rubygems.global.ssl.fastly.net" , and set when restart. need (not tested)

set resp.http.location = regsub(resp.http.location,"^http://",""); set req.http.host = regsub(resp.http.location,"/.*$",""); set req.url = regsub(resp.http.location,"[^/]*",""); 

2) retry , restart different concepts in varnish 4

that why bereq.retries shows 0. need @ req.restarts


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -