title: HAProxy - routing to backend IP based on URL /path?
body: <p>I'm trying to use HAProxy as a dynamic proxy for backend hosts based on partial /path regex match. The use case is routing from an HTTPS frontend to a large number of nodes that come and go frequently, without maintaining an explicit mapping of /path to server hostnames.</p>
  
  <p>Specifically in this case the nodes are members of an Amazon EMR cluster, and I'd like to reverse-proxy/rewrite HTTP requests like:</p>
  
  <pre><code>&lt;haproxy&gt;/emr/ip-99-88-77-66:4040               -&gt; 99.88.77.66:4040
  &lt;haproxy&gt;/emr/ip-55-44-33-22/ganglia            -&gt; 55.44.33.22/ganglia
  &lt;haproxy&gt;/emr/ip-11-11-11-11:8088/cluster/nodes -&gt; 11.11.11.11:8088/cluster/nodes
  ...etc
  </code></pre>
  
  <p>dynamically. </p>
  
  <p>As-in, parse the path beginning at /emr and proxy requests to an IP captured by the regex:</p>
  
  <p><code>emr\/ip-(\d{1,3}-\d{1,3}-\d{1,3}-\d{1,3})(.*)</code></p>
  
  <p>Is this possible with HAProxy? I know it's probably not the right tool for the job, but if possible (even non-performant) I'd like to use the tooling we already have in place.</p>
  
  <p><strong>tl;dr</strong> basically nginx <code>proxy_pass</code>, but with HAProxy and plucking a backend IP from the url.</p>
  
  <p>Thanks!</p>