1

I have several small server and one big server that contain mirror of that several small server. Let's call it Server A, Server B, Server C and Server D for group of small server, and the big server will have Server X as name.

frontend proxy
bind 0.0.0.0:80
mode http
default_backend nodes

backend nodes
    option forwardfor httpchk
    http-request set-header X-Forwarded-Port %[dst_port]
    http-request add-header X-Forwarded-Proto https if { ssl_fc }
    server ServerA (server A IP):80 check
    server ServerB (server B IP):80 check
    server ServerC (server C IP):80 check
    server ServerD (server D IP):80 check
    server ServerX (server X IP):80 backup

Below is a diagram to explain my desired end result.

enter image description here

I want to redirect user to Server X if one of Server A to D is down/unreachable, once the server is gone up the user would have been redirected back to their corresponding server.

  • John search up www.example.com hosted on Server B.
  • Haproxy redirect John to Server B.
  • John is doing something on www.example.com on server B.
  • Server B is down ! John got redirected to Server X.
  • John is doing something on www.example.com on server X.
  • Server B is up ! John got redirected back to server B from Server X.

Pretty sure this can be done with haproxy, but I haven't been able to find a way to do it. Anyone can shed a light to me ? I'm at complete loss now.

1
  • Questions seeking installation, configuration or diagnostic help must include the desired end state, the specific problem or error, sufficient information about the configuration and environment to reproduce it, and attempted solutions. Questions without a clear problem statement are not useful to other readers and are unlikely to get good
    – djdomi
    Commented Jun 5, 2022 at 6:33

3 Answers 3

0
+50

ok. I get what you want now.

Create A, B, C, D different pools.

backend nodesA option forwardfor httpchk http-request set-header X-Forwarded-Port %[dst_port] http-request add-header X-Forwarded-Proto https if { ssl_fc } server ServerA (server A IP):80 check server ServerX (server X IP):80 check

backend nodesB option forwardfor httpchk http-request set-header X-Forwarded-Port %[dst_port] http-request add-header X-Forwarded-Proto https if { ssl_fc } server ServerA (server B IP):80 check server ServerX (server X IP):80 check

And on server A and X, you either set IP for each service to failover to, or a virtualhost responding to a specific domain name. (Sorry, I can`t give more details as you did not specify which technology are...

2
  • Shouldn't server X marked backup and not check ?
    – Liso
    Commented Jun 7, 2022 at 4:54
  • You are correct. I did a copy paste and didn't check back. Sorry.
    – yield
    Commented Jun 7, 2022 at 12:45
0

I am not sure why John would want or should be aware that if he call www.example.com he will end up on server A, B, C or any specific server for that matter.

John only call you domain and expect it to work. Final.

If one of the server un the pool fails, he will get answer by another that will give him the same answer (ex. A fails, any other will answer instead). They already are backup server of each others.

Now. if you want server X to always be the fail over or A, B, C or D, you would need to create different pools including only A and X, B and X and so forth.

However, this also mean that you would have different domain and IP address OR! same domain with same IP but different port for each pool.

If your intention have other reasons, you need to explain because I don't get where you try to go with this. Sorry. Hope this helps.

P.S: You might also want to add a sticky session on your session if you want you user to always get the same server to answer (unless the server fails) in case you user is logging in a application server.

1
  • Yes, each server (Server A to D) host webapp with each different domain, and server X had copies for every web app hosted on Server A to D. I want if any of server A to D goes down, the user got redirected to temporary server (Server X), and redirected back once the original server goes up. I hope that's clear because I'm not too fluent in english.
    – Liso
    Commented Jun 6, 2022 at 12:42
0

You drawing might not be correct may be.... I see you also have multiple HAProxy servers...

In that case, you want a vIP (Virtual IP in front of them) that will load balance for you. I won`t explain how to do that here, but some cloud provider will have easy to configure service for that. If you want to manually do that, that is another story.

That done, all of your HAProxy will have 1 pool with sticky session and only have in their pool server A and X, B and X, C and X and D and X.

That is another design.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .