Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haproxy 503 Service Unavailable . No server is available to handle this request

Tags:

haproxy

How does haproxy deal with static file , like .css, .js, .jpeg ? When I use my configure file , my brower says :

503 Service Unavailable

No server is available to handle this request.

This my config :

global
  daemon
  group root
  maxconn  4000
  pidfile  /var/run/haproxy.pid
  user root

defaults
  log  global
  option  redispatch
  maxconn 65535
  contimeout 5000
  clitimeout 50000
  srvtimeout 50000
  retries  3
  log 127.0.0.1 local3
  timeout  http-request 10s
  timeout  queue 1m
  timeout  connect 10s
  timeout  client 1m
  timeout  server 1m
  timeout  check 10s


listen dashboard_cluster :8888
  mode http
  stats refresh 5s
  balance roundrobin
  option httpclose
  option tcplog
  #stats realm Haproxy \ statistic
  acl url_static path_beg -i /static
  acl url_static path_end -i .css .jpg .jpeg .gif .png .js
  use_backend static_server if url_static

backend static_server
  mode http
  balance roundrobin
  option httpclose
  option tcplog
  stats realm Haproxy \ statistic
  server controller1 10.0.3.139:80 cookie controller1 check inter 2000 rise 2 fall 5
  server controller2 10.0.3.113:80 cookie controller2 check inter 2000 rise 2 fall 5

Does my file wrong ? What should I do to solve this problem ? ths !

like image 519
changzhi Avatar asked Jan 02 '14 10:01

changzhi


2 Answers

What I think is the cause:

There was no default_backend defined. 503 will be sent by HAProxy---this will appear as NOSRV in the logs.

Another Possible Cause

Based on one of my experiences, the HTTP 503 error I receive was due to my 2 bindings I have for the same IP and port x.x.x.x:80.

frontend test_fe
     bind x.x.x.x:80
     bind x.x.x.x:443 ssl blah

     # more config here

frontend conflicting_fe
     bind x.x.x.x:80

     # more config here

Haproxy configuration check does not warn you about it and netstat doesn't show you 2 LISTEN entries, that's why it took a while to realize what's going on.

This can also happen if you have 2 haproxy services running. Please check the running processes and terminate the older one.

like image 54
Ianthe the Duke of Nukem Avatar answered Oct 11 '22 22:10

Ianthe the Duke of Nukem


Try making the timers bigger and check that the server is reachable.

From the HAproxy docs:

It can happen from many reasons:

The status code is always 3-digit. The first digit indicates a general status :
 - 1xx = informational message to be skipped (eg: 100, 101)
 - 2xx = OK, content is following   (eg: 200, 206)
 - 3xx = OK, no content following   (eg: 302, 304)
 - 4xx = error caused by the client (eg: 401, 403, 404)
 - 5xx = error caused by the server (eg: 500, 502, 503)

  503  when no server was available to handle the request, or in response to
        monitoring requests which match the "monitor fail" condition

  When a server's maxconn is reached, connections are left pending in a queue
  which may be server-specific or global to the backend. In order not to wait
  indefinitely, a timeout is applied to requests pending in the queue. If the
  timeout is reached, it is considered that the request will almost never be
  served, so it is dropped and a 503 error is returned to the client.

if you see SC in the logs:

SC   The server or an equipment between it and haproxy explicitly refused
          the TCP connection (the proxy received a TCP RST or an ICMP message
          in return). Under some circumstances, it can also be the network
          stack telling the proxy that the server is unreachable (eg: no route,
          or no ARP response on local network). When this happens in HTTP mode,
          the status code is likely a 502 or 503 here.

Check ACLs, check timeouts... and check the logs, that's the most important...

like image 4
gleb glazkov Avatar answered Oct 11 '22 23:10

gleb glazkov