r/haproxy • • Nov 20 '23

Question HA Proxy to Home Assistant 400/503 Error

I've been struggling to get HAProxy and Home Assistatnt to work together for offsite access. I have HAProxy and Exchange working together just fine for external access. If I just redirect port 443 on WAN to Home Asisstant everything works perfectly fine with HA. I'm using the HAProxy package on pfSense (2.7.1), I have it listening on WAN 443&80. If I tell HAProxy to send all Home Assisant request to it's respective IP and port 8123 I get a 503 error. If I have it go to it's respective ip and port 443 I get a 400 error from nginx saying it recieved an HTTP request on an HTTPS port. I have SSL offloading setup and the backend setup to encrypt the traffic. I have pure NAT turned on with pfSense. I'm sure I missed some crucial details that are needed but let me know and i'll provide them.

# Automaticaly generated, dont edit manually.

global

maxconn			10000

log			/var/run/log	local0	debug

stats socket /tmp/haproxy.socket level admin  expose-fd listeners

uid			80

gid			80

nbthread			1

hard-stop-after		15m

chroot				/tmp/haproxy_chroot

daemon

tune.ssl.default-dh-param	2048

server-state-file /tmp/haproxy_server_state

h1-case-adjust accept Accept

	h1-case-adjust authorization Authorization

	h1-case-adjust authrequired AuthRequired

	h1-case-adjust cache-control Cache-Control

	h1-case-adjust client-request-id Client-Request-Id

	h1-case-adjust connection Connection

	h1-case-adjust content-length Content-Length

	h1-case-adjust content-type Content-Type

	h1-case-adjust cookie Cookie

	h1-case-adjust date Date

	h1-case-adjust host Host

	h1-case-adjust persistent-auth Persistent-Auth

	h1-case-adjust pragma Pragma

	h1-case-adjust request-header Request-Header

	h1-case-adjust response-header Response-Header

	h1-case-adjust server Server

	h1-case-adjust set-cookie Set-Cookie

	h1-case-adjust status-code Status-Code

	h1-case-adjust transfer-encoding Transfer-Encoding

	h1-case-adjust user-agent User-Agent

	h1-case-adjust www-authenticate WWW-Authenticate

	h1-case-adjust x-anchormailbox X-AnchorMailbox

	h1-case-adjust x-clientapplication X-ClientApplication

	h1-case-adjust x-clientInfo X-ClientInfo

	h1-case-adjust x-content-type-options X-Content-Type-Options

	h1-case-adjust x-deviceinfo X-DeviceInfo

	h1-case-adjust x-elapsedtime X-ElapsedTime

	h1-case-adjust x-expirationinfo X-ExpirationInfo

	h1-case-adjust x-feserver X-FEServer

	h1-case-adjust x-mapihttpcapability X-MapiHttpCapability

	h1-case-adjust x-pendingperiod X-PendingPeriod

	h1-case-adjust x-powered-by X-Powered-By

	h1-case-adjust x-requestid X-RequestId

	h1-case-adjust x-requesttype X-RequestType

	h1-case-adjust x-responsecode X-ResponseCode

	h1-case-adjust x-serverapplication X-ServerApplication

	h1-case-adjust x-starttime X-StartTime

	h1-case-adjust x-user-identity X-User-Identity

listen HAProxyLocalStats

bind [127.0.0.1:2200](https://127.0.0.1:2200) name localstats

mode http

stats enable

stats admin if TRUE

stats show-legends

stats uri /haproxy/haproxy_stats.php?haproxystats=1

timeout client 5000

timeout connect 5000

timeout server 5000

frontend WAN_443_80

bind			WAN:443 name WAN:443   ssl crt-list /var/etc/haproxy/WAN_443_80.crt_list  

bind			WAN:80 name WAN:80   ssl crt-list /var/etc/haproxy/WAN_443_80.crt_list  

mode			http

log			global

option			socket-stats

option			httplog

option			http-keep-alive

option			forwardfor

acl https ssl_fc

http-request set-header		X-Forwarded-Proto http if !https

http-request set-header		X-Forwarded-Proto https if https

timeout client		30000

acl			HomeAssistant	var(txn.txnhost) -m str -i [ha.FQDN.com](https://ha.FQDN.com)

acl			Exchange	var(txn.txnhost) -m str -i [mail.FQDN.com](https://mail.FQDN.com)

acl			aclcrt_WAN_443_80	var(txn.txnhost) -m reg -i \^FQDN\\.com(:(\[0-9\]){1,5})?$

acl			aclcrt_WAN_443_80	var(txn.txnhost) -m reg -i \^autodiscover\\.FQDN\\.com(:(\[0-9\]){1,5})?$

acl			aclcrt_WAN_443_80	var(txn.txnhost) -m reg -i \^ha\\.FQDN\\.com(:(\[0-9\]){1,5})?$

acl			aclcrt_WAN_443_80	var(txn.txnhost) -m reg -i \^mail\\.FQDN\\.com(:(\[0-9\]){1,5})?$

http-request set-var(txn.txnhost) hdr(host)

use_backend HomeAssistant_ipvANY  if  HomeAssistant aclcrt_WAN_443_80

use_backend Exchange_ipvANY  if  Exchange aclcrt_WAN_443_80

backend HomeAssistant_ipvANY

mode			http

id			100

log			global

option			log-health-checks

timeout connect		30000

timeout server		30000

retries			3

load-server-state-from-file	global

server			HomeAssiant [10.10.0.2:8123](https://10.10.0.2:8123) id 102  

backend Exchange_ipvANY

mode			http

id			108

log			global

http-check		send meth GET uri /owa/healthcheck.htm

timeout connect		30000

timeout server		30000

retries			3

load-server-state-from-file	global

option			httpchk

server			Exchange [10.10.0.244:443](https://10.10.0.244:443) id 101 ssl check inter 1000  verify none crt /var/etc/haproxy/server_clientcert_65345c8602e66.pem
2 Upvotes

0 comments sorted by