Raja
Raja

Reputation: 55

HAproxy-reverse proxy for multiple domains - 503 service unavailable

I have try to setup a HAproxy - reverse proxy for multiple domains.But when i tried the HAProxy url in browser, it shows "503 - service unavailable".

Am trying to setup this,I have four domains- when any one hits the proxy server url ,the request has to go the particular domain belongs to the request.

Below my haproxy config file.

log         127.0.0.1 local2
chroot      /var/lib/haproxy
pidfile     /var/run/haproxy.pid
maxconn     4000
user        haproxy
group       haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats

defaults

mode                    http
log                     global
option                  httplog
option                  dontlognull
option                  http-server-close
option                  forwardfor
option                  redispatch
retries                 3
timeout http-request    10s
timeout queue           1m
timeout connect         10s
timeout client          1m
timeout server          1m
timeout http-keep-alive 10s
timeout check           10s
maxconn                 3000

frontend http-in bind *:80

    acl host1 hdr(host) -i xyz.com
    acl host2 hdr(host) -i abc.com
    acl host3 hdr(host) -i ghy.com
    acl host4 hdr(host) -i klm.com

    use_backend xyz if host1
    use_backend abc if host2
    use_backend ghy if host3
    use_backend klm if host4

backend xyz

    mode    http
    balance     roundrobin
    option forwardfor
    server s2 xyz.com:80 check

backend abc

    mode    http
    balance     roundrobin
    option forwardfor
    server s1 abc.com:80 check

backend ghy

    mode    http
    balance     roundrobin
    option forwardfor
    server s4 ghy.com:80 check

backend klm

    mode    http
    balance     roundrobin
    option forwardfor
    server s3 klm.com:443 check

listen webinterface

bind 0.0.0.0:9200

mode http

stats enable

stats uri /

stats realm Strictly\ Private

stats auth admin:admin@123


Please help me to fix this issue.

Thanks in Advance.

Upvotes: 0

Views: 3994

Answers (1)

Matt Rice
Matt Rice

Reputation: 696

Getting 503 - service unavailable from haproxy indicates that the backend server is not serving requests properly - if you check your stats page (e.g. http://localhost:9200/), the server will be shown in red (if the server were healthy, it would be shown in green; a healthy backup server would be shown in blue).

Since your server lines include the check keyword, haproxy is periodically polling each backend server to see if the server is "healthy" - that is, if it returns a 2xx-3xx HTTP status (for http checks).

You have several options:

  • Remove check from your server lines - haproxy assumes the servers are available by default.
  • Leave check on your server lines but configure the httpchk (this can be done for each backend). For example: option forwardfor option httpchk HEAD / HTTP/1.1\r\nUser-Agent:\ HAProxy\r\nHost:\ server s2 xyz.com:80 check

Do not forget to reload/restart haproxy after making config changes!

Upvotes: 3

Related Questions