vendredi 24 février 2017

Build a URL on varnish changing backend

Hi had deployed the 1st stage for the new version of an existing web site, I need to redirect some HTTP request from new site to old site, I'd declare a director_1 for new site and a director_2 for old site:

backend server1 {
    .host = "172.16.1.24";
}
backend server2 {
    .host = "172.16.1.25";
}

backend oldWeb1 {
    .host = "172.16.1.41";
}

backend oldWeb2 {
    .host = "172.16.1.42";
}


sub vcl_init {
    new director_1 = directors.round_robin();
    bar.add_backend(server1);
    bar.add_backend(server2);

    new director_2 = directors.round_robin();
    old.add_backend(oldWeb1);
    old.add_backend(oldWeb2);

sub vcl_recv {

I'd tried to build the New URL on vcl_recv subroutine from many ways like:

-Changing the req backend

if (req.url ~ "^/toredirect") {
        set req.backend_hint = director_2.backend();
}
else {
        set req.backend_hint = director_1.backend();
}   

-Rewriting the URL

if (req.url ~ "^/toredirect") {
        set req.backend_hint = director_2.backend() + "/toredirect";
}
else {
        set req.backend_hint = director_1.backend();
} 

But When I go to http://varnishServerIP/toredirect not do that i expect and redirect error 404 page, anybody can help me!




Aucun commentaire:

Enregistrer un commentaire