title: haproxy: get the host name
body: <p>I am trying to get the requester host/ip as it comes to haproxy node.
  My haproxy config is as below:</p>
  
  <pre><code>frontend www-http
      bind *:9000
      http-request redirect location https://%fi:9143
  
  frontend www-https
      bind *:9143 ssl crt /root/keys.pem
      reqadd X-Forwarded-Proto:\ https
      default_backend www-backend
  
  backend www-backend
      balance roundrobin
      cookie SERVERID insert indirect nocache
      server server1 1.1.1.1:9080 cookie server1 weight 1 maxconn 1024 check
  </code></pre>
  
  <p>So here, if any http request comes, then I need to forward to https.
  Now request may come either with ip address or hostname in fully qualified form, like</p>
  
  <pre><code>http://10.10.10.10:9000 
  </code></pre>
  
  <p>this needs to be forwarded to <a href="https://10.10.10.10:9143" rel="nofollow noreferrer">https://10.10.10.10:9143</a></p>
  
  <p>Again, the request may come hostname in fully qualified form, like</p>
  
  <pre><code>http://myhost.domain.com:9000
  </code></pre>
  
  <p>this needs to be forwarded to <a href="https://myhost.domain.com:9143" rel="nofollow noreferrer">https://myhost.domain.com:9143</a></p>
  
  <p>basically 10.10.10.10 and myhost.domain.com is same system.</p>
  
  <p>Now with the above haproxy configuration, I am not able to get the below, as it is %fi (frontend_ip), so it is redirecting to <a href="https://10.10.10.10:9143" rel="nofollow noreferrer">https://10.10.10.10:9143</a></p>
  
  <p>So my question is how I can get the haproxy node's ip/host as it comes to haproxy.</p>
  
  <p>I tried below options, which did not work:</p>
  
  <pre><code>http-request redirect location https://%f:9143
  http-request redirect location https://%[req.hdr(Host)]:9143
  </code></pre>
  
  <p>from <a href="https://www.haproxy.com/doc/aloha/7.0/haproxy/log_format_rules.html" rel="nofollow noreferrer">https://www.haproxy.com/doc/aloha/7.0/haproxy/log_format_rules.html</a></p>