2015-11-12 5 views
0

Я пытаюсь настроить сервер лака (4) с 2 backend. Однако, когда я пытаюсь получить к нему доступ с двумя разными URL-адресами, он всегда возвращается к серверному серверу. Вот соответствующие части моего .vcl-файла.Лак с 2 backend, всегда возвращается к первому backend

конфигурации сервера

Backend:

backend server1 { 
    .host = "127.0.0.1"; 
    .port = "83"; 
    .connect_timeout = 600s; 
    .first_byte_timeout = 600s; 
    .between_bytes_timeout = 600s; 
} 

backend server2 { 
    .host = "127.0.0.1"; 
    .port = "84"; 
    .connect_timeout = 600s; 
    .first_byte_timeout = 600s; 
    .between_bytes_timeout = 600s; 
} 

И секция vcl_recv

import std; 
# Respond to incoming requests. 
sub vcl_recv { 

     if (req.method == "BAN") { 
       # Same ACL check as above: 
       if (!client.ip ~ purge) { 
         return(synth(403, "Not allowed.")); 
       } 
       ban("req.http.host == " + req.http.host + 
         " && req.url == " + req.url); 

       # Throw a synthetic page so the 
       # request won't go to the backend. 
       return(synth(200, "Ban added")); 
     } else if (req.method == "PURGE") { 
       if (!client.ip ~ purge) { 
         return(synth(405,"Not allowed.")); 
       } 
       return (purge); 
     } else if (req.method != "GET" && req.method != "POST" && req.method != "DELETE" && req.method != "PUT") { 
       return(synth(405, "Method not allowed")); 
     } 

    if (req.url ~ "^/piwik/piwik.php") { 
    set req.backend_hint = server1; 
    return(pass); 
    } else if (req.url ~ "^/piwik/piwik.js") { 
    set req.backend_hint = server1; 
    return(pass); 
    } else if (req.url ~ "^/piwik" ) { 
# error 404 "Not found"; 
#  return(synth(404, "File not found")); 
    set req.url = "/404-page-not-found"; 
    } else if (req.url ~"/node/(\d+)/(.+)$") { 
#  return(synth(404, "File not found")); 
    set req.url = "/404-page-not-found"; 
    } else if (req.url ~"/monitoring") { 
#  return(synth(404, "File not found")); 
#  set req.url = "/404-page-not-found"; 
     return(pass); 
    } else if (req.url ~"^/user") { 
#  return(synth(404, "File not found")); 
    set req.url = "/404-page-not-found"; 
    } else if (req.url ~ "^/admin") { 
#  return(synth(404, "File not found")); 
    set req.url = "/404-page-not-found"; 
    } else if (req.url ~ "^/team") { 
#  return(synth(404, "File not found")); 
    set req.url = "/404-page-not-found"; 
    } else if (req.url ~ "^/administer") { 
#  return(synth(404, "File not found")); 
    set req.url = "/404-page-not-found"; 
    } else if (req.url ~ "/edit?$") { 
#  return(synth(404, "File not found")); 
    set req.url = "/404-page-not-found"; 
    } else if (req.url ~ "/add?$") { 
#  return(synth(404, "File not found")); 
    set req.url = "/404-page-not-found"; 
    } else if (req.url ~ "^(www\.)?server2.com$") { 
    set req.backend_hint = server2; 
    } else if (req.url ~ "^(www\.)?server1.com$") { 
    set req.backend_hint = server1.com; 
    } 

Если добавить следующее заявление в нижней части раздела vcl_recv то я могу получить доступ к бэкенд SERVER2 в:

else { 
    set req.backend_hint = server2; 
} 

ответ

0

В вашем VLC вы используете

req.url ~ "^(www\.)?server2.com$" 

но req.url не содержит имя хоста. То, что вы хотите сделать, это, вероятно,

req.http.host ~ "^(www\.)?server2\.com$" 

или, может быть

req.http.host ~ "^(www\.)?server2\.com$" && req.url ~ "^/$" 

 Смежные вопросы

  • Нет связанных вопросов^_^