The backend is not forwarding traffic to the server and returns 503 service unavailable. My server requires the exact URL and headers. If the header is not set, the server will return 401 unauthorized and if the URL is not set, the server will return 404 Not found.
My cfg file
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
I am testing as following
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)
Response
<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>
HAProxy Logs
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"
Please guide me what's wrong here.
semanage port --add --type http_port_t --proto tcp 32401
I added this line to allow traffic on port 32401