HAProxy not recognizing host headers? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Come Celebrate our 10 Year Anniversary!How to divert traffic based on hostname using HAProxy?HAproxy roundrobin balancing does not appear to be distributing evenlyHaProxy + IIS pages gradually get slowerHaProxy - Http and SSL pass through confighaproxy forward uri to root of another serverHaproxy logging not workHA-Proxy 301 re-direct: https to https://wwwHaProxy giving - 503 Service UnavailableHAProxy not logging all requestsHaproxy doesn't go to the write backend after coming back from Nginx Reverse Proxyopenldap with haproxy - (ldap_result() failed: Can't contact LDAP server)

Why doesn't the university give past final exams' answers?

What *exactly* is electrical current, voltage, and resistance?

Why is one lightbulb in a string illuminated?

How do I deal with an erroneously large refund?

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?

tabularx column has extra padding at right?

Weaponising the Grasp-at-a-Distance spell

What's the difference between using dependency injection with a container and using a service locator?

Can I ask an author to send me his ebook?

Has a Nobel Peace laureate ever been accused of war crimes?

What helicopter has the most rotor blades?

Can I take recommendation from someone I met at a conference?

What were wait-states, and why was it only an issue for PCs?

Like totally amazing interchangeable sister outfit accessory swapping or whatever

Why do people think Winterfell crypts is the safest place for women, children & old people?

Coin Game with infinite paradox

2 sample t test for sample sizes - 30,000 and 150,000

Is "ein Herz wie das meine" an antiquated or colloquial use of the possesive pronoun?

Etymology of 見舞い

Is my guitar’s action too high?

Does using the Inspiration rules for character defects encourage My Guy Syndrome?

Is there a verb for listening stealthily?

Raising a bilingual kid. When should we introduce the majority language?

Help Recreating a Table



HAProxy not recognizing host headers?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Come Celebrate our 10 Year Anniversary!How to divert traffic based on hostname using HAProxy?HAproxy roundrobin balancing does not appear to be distributing evenlyHaProxy + IIS pages gradually get slowerHaProxy - Http and SSL pass through confighaproxy forward uri to root of another serverHaproxy logging not workHA-Proxy 301 re-direct: https to https://wwwHaProxy giving - 503 Service UnavailableHAProxy not logging all requestsHaproxy doesn't go to the write backend after coming back from Nginx Reverse Proxyopenldap with haproxy - (ldap_result() failed: Can't contact LDAP server)



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have been trying to configure HAProxy to send traffic to different backend servers based on hostnames. I tried using the directions found in How to divert traffic based on hostname using HAProxy? but unfortunately am not having luck.



I am trying to have it so that if a client goes to bk1.domain.com:80, traffic is sent to the "backend1" backend. Similarly, if someone goes to bk2.domain.com:80, traffic should be sent to the "backend2" backend. All other traffic should be sent to the "default" backend. For clarification, domain.com, bk1.domain.com, bk2.domain.com all resolve to the same IP address.



Unfortunately, when going to bk1.domain.com or bk2.domain.com, the "default" backend is used for all requests. It seems that HAProxy is not recognizing the host headers and as a result is unable to forward requests to the appropriate backend.



Below is the current haproxy.cfg. Any help is appreciated.



global
log 127.0.0.1 local0
maxconn 4096
user haproxy
group haproxy
daemon

defaults
log global
retries 3
option redispatch
maxconn 2000
timeout http-request 5s
timeout connect 5s
timeout client 30s
timeout server 10s

frontend all_clients
bind 0.0.0.0:80
acl back1 hdr(host) -i bk1.domain.com
acl back2 hdr(host) -i bk2.domian.com
use_backend backend1 if back1
use_backend backend2 if back2
default_backend default

backend default
balance roundrobin
server a1 192.168.0.1:8080
server a2 192.168.0.2:8080
server a3 192.168.0.3:8080

backend backend1
balance roundrobin
server b1 10.0.0.1:8080
server b2 10.0.0.2:8080

backend backend2
balance roundrobin
server c1 172.16.0.1:8080
server c2 172.16.0.2:8080









share|improve this question
























  • Have you tried without the dots?

    – JamesRyan
    Jan 30 '16 at 3:01











  • I just tried "acl back1 hdr_beg(host) -i bk1" without the period at the end and unfortunately all requests are still going to the "default" backend.

    – Ron F
    Jan 30 '16 at 3:05






  • 1





    This pattern definately works, i'm using it. Try putting default_backend at bottom of section and all acls before use_backends. Try renaming the backends so they arnt the same as the text you match. try using 'hdr(host) -i bk1.domain.com'. Also try not repeating server names, you have 3 server1s currently, they might need to be unique. It will be something simple like that.

    – JamesRyan
    Jan 30 '16 at 3:28












  • Thanks for your suggestions. I’ve seen this pattern used on multiple sites as well so I’m not sure why it is not working for me. I implemented each suggestion of yours one at a time, restarted haproxy each time and then checked to see if the problem was fixed. I even restarted the entire server. Unfortunately, after implementing everything, all requests are still being forwarded to the “default” backend. I have updated the original post with all your suggestions.

    – Ron F
    Jan 30 '16 at 3:54











  • What happens if you take default_backend out altogether?

    – JamesRyan
    Jan 30 '16 at 12:48

















1















I have been trying to configure HAProxy to send traffic to different backend servers based on hostnames. I tried using the directions found in How to divert traffic based on hostname using HAProxy? but unfortunately am not having luck.



I am trying to have it so that if a client goes to bk1.domain.com:80, traffic is sent to the "backend1" backend. Similarly, if someone goes to bk2.domain.com:80, traffic should be sent to the "backend2" backend. All other traffic should be sent to the "default" backend. For clarification, domain.com, bk1.domain.com, bk2.domain.com all resolve to the same IP address.



Unfortunately, when going to bk1.domain.com or bk2.domain.com, the "default" backend is used for all requests. It seems that HAProxy is not recognizing the host headers and as a result is unable to forward requests to the appropriate backend.



Below is the current haproxy.cfg. Any help is appreciated.



global
log 127.0.0.1 local0
maxconn 4096
user haproxy
group haproxy
daemon

defaults
log global
retries 3
option redispatch
maxconn 2000
timeout http-request 5s
timeout connect 5s
timeout client 30s
timeout server 10s

frontend all_clients
bind 0.0.0.0:80
acl back1 hdr(host) -i bk1.domain.com
acl back2 hdr(host) -i bk2.domian.com
use_backend backend1 if back1
use_backend backend2 if back2
default_backend default

backend default
balance roundrobin
server a1 192.168.0.1:8080
server a2 192.168.0.2:8080
server a3 192.168.0.3:8080

backend backend1
balance roundrobin
server b1 10.0.0.1:8080
server b2 10.0.0.2:8080

backend backend2
balance roundrobin
server c1 172.16.0.1:8080
server c2 172.16.0.2:8080









share|improve this question
























  • Have you tried without the dots?

    – JamesRyan
    Jan 30 '16 at 3:01











  • I just tried "acl back1 hdr_beg(host) -i bk1" without the period at the end and unfortunately all requests are still going to the "default" backend.

    – Ron F
    Jan 30 '16 at 3:05






  • 1





    This pattern definately works, i'm using it. Try putting default_backend at bottom of section and all acls before use_backends. Try renaming the backends so they arnt the same as the text you match. try using 'hdr(host) -i bk1.domain.com'. Also try not repeating server names, you have 3 server1s currently, they might need to be unique. It will be something simple like that.

    – JamesRyan
    Jan 30 '16 at 3:28












  • Thanks for your suggestions. I’ve seen this pattern used on multiple sites as well so I’m not sure why it is not working for me. I implemented each suggestion of yours one at a time, restarted haproxy each time and then checked to see if the problem was fixed. I even restarted the entire server. Unfortunately, after implementing everything, all requests are still being forwarded to the “default” backend. I have updated the original post with all your suggestions.

    – Ron F
    Jan 30 '16 at 3:54











  • What happens if you take default_backend out altogether?

    – JamesRyan
    Jan 30 '16 at 12:48













1












1








1








I have been trying to configure HAProxy to send traffic to different backend servers based on hostnames. I tried using the directions found in How to divert traffic based on hostname using HAProxy? but unfortunately am not having luck.



I am trying to have it so that if a client goes to bk1.domain.com:80, traffic is sent to the "backend1" backend. Similarly, if someone goes to bk2.domain.com:80, traffic should be sent to the "backend2" backend. All other traffic should be sent to the "default" backend. For clarification, domain.com, bk1.domain.com, bk2.domain.com all resolve to the same IP address.



Unfortunately, when going to bk1.domain.com or bk2.domain.com, the "default" backend is used for all requests. It seems that HAProxy is not recognizing the host headers and as a result is unable to forward requests to the appropriate backend.



Below is the current haproxy.cfg. Any help is appreciated.



global
log 127.0.0.1 local0
maxconn 4096
user haproxy
group haproxy
daemon

defaults
log global
retries 3
option redispatch
maxconn 2000
timeout http-request 5s
timeout connect 5s
timeout client 30s
timeout server 10s

frontend all_clients
bind 0.0.0.0:80
acl back1 hdr(host) -i bk1.domain.com
acl back2 hdr(host) -i bk2.domian.com
use_backend backend1 if back1
use_backend backend2 if back2
default_backend default

backend default
balance roundrobin
server a1 192.168.0.1:8080
server a2 192.168.0.2:8080
server a3 192.168.0.3:8080

backend backend1
balance roundrobin
server b1 10.0.0.1:8080
server b2 10.0.0.2:8080

backend backend2
balance roundrobin
server c1 172.16.0.1:8080
server c2 172.16.0.2:8080









share|improve this question
















I have been trying to configure HAProxy to send traffic to different backend servers based on hostnames. I tried using the directions found in How to divert traffic based on hostname using HAProxy? but unfortunately am not having luck.



I am trying to have it so that if a client goes to bk1.domain.com:80, traffic is sent to the "backend1" backend. Similarly, if someone goes to bk2.domain.com:80, traffic should be sent to the "backend2" backend. All other traffic should be sent to the "default" backend. For clarification, domain.com, bk1.domain.com, bk2.domain.com all resolve to the same IP address.



Unfortunately, when going to bk1.domain.com or bk2.domain.com, the "default" backend is used for all requests. It seems that HAProxy is not recognizing the host headers and as a result is unable to forward requests to the appropriate backend.



Below is the current haproxy.cfg. Any help is appreciated.



global
log 127.0.0.1 local0
maxconn 4096
user haproxy
group haproxy
daemon

defaults
log global
retries 3
option redispatch
maxconn 2000
timeout http-request 5s
timeout connect 5s
timeout client 30s
timeout server 10s

frontend all_clients
bind 0.0.0.0:80
acl back1 hdr(host) -i bk1.domain.com
acl back2 hdr(host) -i bk2.domian.com
use_backend backend1 if back1
use_backend backend2 if back2
default_backend default

backend default
balance roundrobin
server a1 192.168.0.1:8080
server a2 192.168.0.2:8080
server a3 192.168.0.3:8080

backend backend1
balance roundrobin
server b1 10.0.0.1:8080
server b2 10.0.0.2:8080

backend backend2
balance roundrobin
server c1 172.16.0.1:8080
server c2 172.16.0.2:8080






proxy load-balancing haproxy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:14









Community

1




1










asked Jan 30 '16 at 1:53









Ron FRon F

63




63












  • Have you tried without the dots?

    – JamesRyan
    Jan 30 '16 at 3:01











  • I just tried "acl back1 hdr_beg(host) -i bk1" without the period at the end and unfortunately all requests are still going to the "default" backend.

    – Ron F
    Jan 30 '16 at 3:05






  • 1





    This pattern definately works, i'm using it. Try putting default_backend at bottom of section and all acls before use_backends. Try renaming the backends so they arnt the same as the text you match. try using 'hdr(host) -i bk1.domain.com'. Also try not repeating server names, you have 3 server1s currently, they might need to be unique. It will be something simple like that.

    – JamesRyan
    Jan 30 '16 at 3:28












  • Thanks for your suggestions. I’ve seen this pattern used on multiple sites as well so I’m not sure why it is not working for me. I implemented each suggestion of yours one at a time, restarted haproxy each time and then checked to see if the problem was fixed. I even restarted the entire server. Unfortunately, after implementing everything, all requests are still being forwarded to the “default” backend. I have updated the original post with all your suggestions.

    – Ron F
    Jan 30 '16 at 3:54











  • What happens if you take default_backend out altogether?

    – JamesRyan
    Jan 30 '16 at 12:48

















  • Have you tried without the dots?

    – JamesRyan
    Jan 30 '16 at 3:01











  • I just tried "acl back1 hdr_beg(host) -i bk1" without the period at the end and unfortunately all requests are still going to the "default" backend.

    – Ron F
    Jan 30 '16 at 3:05






  • 1





    This pattern definately works, i'm using it. Try putting default_backend at bottom of section and all acls before use_backends. Try renaming the backends so they arnt the same as the text you match. try using 'hdr(host) -i bk1.domain.com'. Also try not repeating server names, you have 3 server1s currently, they might need to be unique. It will be something simple like that.

    – JamesRyan
    Jan 30 '16 at 3:28












  • Thanks for your suggestions. I’ve seen this pattern used on multiple sites as well so I’m not sure why it is not working for me. I implemented each suggestion of yours one at a time, restarted haproxy each time and then checked to see if the problem was fixed. I even restarted the entire server. Unfortunately, after implementing everything, all requests are still being forwarded to the “default” backend. I have updated the original post with all your suggestions.

    – Ron F
    Jan 30 '16 at 3:54











  • What happens if you take default_backend out altogether?

    – JamesRyan
    Jan 30 '16 at 12:48
















Have you tried without the dots?

– JamesRyan
Jan 30 '16 at 3:01





Have you tried without the dots?

– JamesRyan
Jan 30 '16 at 3:01













I just tried "acl back1 hdr_beg(host) -i bk1" without the period at the end and unfortunately all requests are still going to the "default" backend.

– Ron F
Jan 30 '16 at 3:05





I just tried "acl back1 hdr_beg(host) -i bk1" without the period at the end and unfortunately all requests are still going to the "default" backend.

– Ron F
Jan 30 '16 at 3:05




1




1





This pattern definately works, i'm using it. Try putting default_backend at bottom of section and all acls before use_backends. Try renaming the backends so they arnt the same as the text you match. try using 'hdr(host) -i bk1.domain.com'. Also try not repeating server names, you have 3 server1s currently, they might need to be unique. It will be something simple like that.

– JamesRyan
Jan 30 '16 at 3:28






This pattern definately works, i'm using it. Try putting default_backend at bottom of section and all acls before use_backends. Try renaming the backends so they arnt the same as the text you match. try using 'hdr(host) -i bk1.domain.com'. Also try not repeating server names, you have 3 server1s currently, they might need to be unique. It will be something simple like that.

– JamesRyan
Jan 30 '16 at 3:28














Thanks for your suggestions. I’ve seen this pattern used on multiple sites as well so I’m not sure why it is not working for me. I implemented each suggestion of yours one at a time, restarted haproxy each time and then checked to see if the problem was fixed. I even restarted the entire server. Unfortunately, after implementing everything, all requests are still being forwarded to the “default” backend. I have updated the original post with all your suggestions.

– Ron F
Jan 30 '16 at 3:54





Thanks for your suggestions. I’ve seen this pattern used on multiple sites as well so I’m not sure why it is not working for me. I implemented each suggestion of yours one at a time, restarted haproxy each time and then checked to see if the problem was fixed. I even restarted the entire server. Unfortunately, after implementing everything, all requests are still being forwarded to the “default” backend. I have updated the original post with all your suggestions.

– Ron F
Jan 30 '16 at 3:54













What happens if you take default_backend out altogether?

– JamesRyan
Jan 30 '16 at 12:48





What happens if you take default_backend out altogether?

– JamesRyan
Jan 30 '16 at 12:48










1 Answer
1






active

oldest

votes


















0














snipped your code, and edited. what you need to do is define an acl, then route based on the acl:



frontend all_clients
bind 0.0.0.0:80
default_backend default
acl back1 if hdr_beg(host) -i bk1.
acl back2 if hdr_beg(host) -i bk2.
use_backend bk1 if back1
use_backend bk2 if back2





share|improve this answer

























  • Your configuration produces errors as it does not appear to be valid syntax but I changed my original post to what I believe you were attempting to do. It is now also using the exact same configuration as posted in serverfault.com/questions/105824/…. Unfortunately, it still is not working properly.

    – Ron F
    Jan 30 '16 at 2:36











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f752807%2fhaproxy-not-recognizing-host-headers%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














snipped your code, and edited. what you need to do is define an acl, then route based on the acl:



frontend all_clients
bind 0.0.0.0:80
default_backend default
acl back1 if hdr_beg(host) -i bk1.
acl back2 if hdr_beg(host) -i bk2.
use_backend bk1 if back1
use_backend bk2 if back2





share|improve this answer

























  • Your configuration produces errors as it does not appear to be valid syntax but I changed my original post to what I believe you were attempting to do. It is now also using the exact same configuration as posted in serverfault.com/questions/105824/…. Unfortunately, it still is not working properly.

    – Ron F
    Jan 30 '16 at 2:36















0














snipped your code, and edited. what you need to do is define an acl, then route based on the acl:



frontend all_clients
bind 0.0.0.0:80
default_backend default
acl back1 if hdr_beg(host) -i bk1.
acl back2 if hdr_beg(host) -i bk2.
use_backend bk1 if back1
use_backend bk2 if back2





share|improve this answer

























  • Your configuration produces errors as it does not appear to be valid syntax but I changed my original post to what I believe you were attempting to do. It is now also using the exact same configuration as posted in serverfault.com/questions/105824/…. Unfortunately, it still is not working properly.

    – Ron F
    Jan 30 '16 at 2:36













0












0








0







snipped your code, and edited. what you need to do is define an acl, then route based on the acl:



frontend all_clients
bind 0.0.0.0:80
default_backend default
acl back1 if hdr_beg(host) -i bk1.
acl back2 if hdr_beg(host) -i bk2.
use_backend bk1 if back1
use_backend bk2 if back2





share|improve this answer















snipped your code, and edited. what you need to do is define an acl, then route based on the acl:



frontend all_clients
bind 0.0.0.0:80
default_backend default
acl back1 if hdr_beg(host) -i bk1.
acl back2 if hdr_beg(host) -i bk2.
use_backend bk1 if back1
use_backend bk2 if back2






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 30 '16 at 16:00

























answered Jan 30 '16 at 2:17









FlashFlash

1,280710




1,280710












  • Your configuration produces errors as it does not appear to be valid syntax but I changed my original post to what I believe you were attempting to do. It is now also using the exact same configuration as posted in serverfault.com/questions/105824/…. Unfortunately, it still is not working properly.

    – Ron F
    Jan 30 '16 at 2:36

















  • Your configuration produces errors as it does not appear to be valid syntax but I changed my original post to what I believe you were attempting to do. It is now also using the exact same configuration as posted in serverfault.com/questions/105824/…. Unfortunately, it still is not working properly.

    – Ron F
    Jan 30 '16 at 2:36
















Your configuration produces errors as it does not appear to be valid syntax but I changed my original post to what I believe you were attempting to do. It is now also using the exact same configuration as posted in serverfault.com/questions/105824/…. Unfortunately, it still is not working properly.

– Ron F
Jan 30 '16 at 2:36





Your configuration produces errors as it does not appear to be valid syntax but I changed my original post to what I believe you were attempting to do. It is now also using the exact same configuration as posted in serverfault.com/questions/105824/…. Unfortunately, it still is not working properly.

– Ron F
Jan 30 '16 at 2:36

















draft saved

draft discarded
















































Thanks for contributing an answer to Server Fault!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f752807%2fhaproxy-not-recognizing-host-headers%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company