HAProxy:如何在主机名而不是IP地址上进行匹配

时间:2019-02-07 21:56:50

标签: haproxy

我正在尝试匹配host请求标头,并使用适当的后端来路由请求。

这是我要匹配的内容(不起作用):

acl from_external_url req.hdr(Host) -i mydomain.com  

# Chrome dev tools network tab does show mydomain.com set as the Host header

但是,匹配直接IP地址是可行的(我不想要):

acl from_external_url req.hdr(Host) -i 22.22.22.22

那么,如何在主机名而不是IP上进行HAProxy路由?

更新1:

use_backend oid_external if from_external_url
use_backend oid_internal if !from_external_url

1 个答案:

答案 0 :(得分:0)

我使用以下方式基于主机名进行路由,因为我大约有12个站点都通过了haproxy。

loadData = ()=> {
  req = new XMLHttpRequest();
  req.open("GET", "https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json" , true);
  req.send();
  req.onload= ()=>{
      json = JSON.parse(req.responseText);
      //create measurements
      const margin = 60
      const width = 1000 - margin;
      const height = 600 - margin;

      //create svg
      const svg = d3.select("svg");
      const chart = svg.append("g")
        .attr("transform", `translate(${margin}, ${margin})`);


      //y-axis: split charts into 2 equal parts using scaling function
      const yScale = d3.scaleLinear()
        .range([height, 0]) //length
        .domain([0,100]); //content

      //create x-axis
      const yAxis = d3.axisLeft(yScale);

      //append y-axis
      chart.append("g")
        .call(yAxis);

       //create x-scale
      const xScale = d3.scaleBand()
        .range([0, width]) //length
        .domain([0,100]) //content
        .padding(0.2);

      //create x-axis
      const xAxis = d3.axisBottom(xScale);

      //append x-axis
      chart.append("g")
        .attr(`transform`, `translate(0, ${height})`)
        .call(xAxis);
   } 
}

loadData();