【问题标题】:Haproxy 503 Service Unavailable . No server is available to handle this requestHaproxy 503 服务不可用。没有可用于处理此请求的服务器
【发布时间】:2016-06-25 04:43:19
【问题描述】:

haproxy 如何处理静态文件,如 .css、.js、.jpeg ?当我使用我的配置文件时,我的浏览器说:

503 服务不可用

没有可用的服务器来处理这个请求。

这是我的配置:

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

我的文件有问题吗?我应该怎么做才能解决这个问题?这个!

【问题讨论】:

    标签: haproxy


    【解决方案1】:

    我认为是什么原因:

    没有定义default_backend。 503 将由 HAProxy 发送——这将在日志中显示为 NOSRV

    另一个可能的原因

    根据我的经验之一,我收到的 HTTP 503 错误是由于我对相同 IP 和端口 x.x.x.x:80 的 2 个绑定。

    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 配置检查不会向您发出警告,netstat 不会向您显示 2 个 LISTEN 条目,这就是为什么需要一段时间才能意识到发生了什么。

    如果您有 2 个haproxy 服务正在运行,也会发生这种情况。请检查正在运行的进程并终止旧的进程。

    【讨论】:

      【解决方案2】:

      尝试将计时器调大,并检查服务器是否可访问。

      来自 HAproxy 文档:

      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.
      

      如果您在日志中看到 SC:

      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.
      

      检查 ACL,检查超时...并检查日志,这是最重要的...

      【讨论】:

        猜你喜欢
        • 2015-06-02
        • 1970-01-01
        • 2021-12-06
        • 1970-01-01
        • 1970-01-01
        • 2016-10-26
        • 2017-01-14
        • 2022-10-13
        • 2022-01-21
        相关资源
        最近更新 更多