HAProxy 503 服务不可用 - 带标头的 POST

HAProxy 503 服务不可用 - 带标头的 POST

后端未将流量转发到服务器并返回 503 服务不可用。我的服务器需要准确的 URL 和标头。如果未设置标头,服务器将返回 401 未授权,如果未设置 URL,服务器将返回 404 未找到。

我的 cfg 文件

global
    log         127.0.0.1 local0 debug
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     1000
    user        haproxy
    group       haproxy
    daemon
    stats socket /var/lib/haproxy/stats

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    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  main 0.0.0.0:80
  option httpclose
  option forwardfor
  reqadd X-Forwarded-Proto:\ http
  http-request add-header X-Forwarded-Proto http

  default_backend             app

backend app
    balance     roundrobin
    server  app1 100.82.185.122:32401

我正在测试如下

import csv
import requests
import time

#url='http://100.82.185.122:32401/services/collector/event' #DIRECT URL 
url='http://100.82.182.73/services/collector/event' #HA Proxy URL
authHeader = {'Authorization': 'Splunk {}'.format('f64e68e1-a6e4-46a1-8fe3-131023886841')}
reader = csv.DictReader(open('overheating_.csv'))
for row in reader: 
    #row['SystemUsage.AggregateUsage'] = 17
    #row['FanSensor.RPMReading'] = 3
    jsonDict = {"index":"dltk-test", "source":"csv", "sourcetype":"all-idrac", "event": row }
    #print (row)
    r = requests.post(url, headers=authHeader, json=jsonDict, verify=False)
    print (r.text)
    time.sleep(1)

回复

<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>

HAProxy 日志

Jun 28 15:30:51 localhost haproxy[25389]: 100.82.183.41:41182 [28/Jun/2022:15:30:51.906] main app/app1 0/0/-1/-1/0 503 212 - - SC-- 0/0/0/0/3 0/0 "POST /services/collector/event HTTP/1.1"
Jun 28 15:30:52 localhost haproxy[25389]: 100.82.183.41:41184 [28/Jun/2022:15:30:52.913] main app/app1 0/0/-1/-1/0 503 212 - - SC-- 0/0/0/0/3 0/0 "POST /services/collector/event HTTP/1.1"

请指导我这里出了什么问题。

答案1

semanage port --add --type http_port_t --proto tcp 32401

解决了这个问题

相关内容