Skip to content

Instantly share code, notes, and snippets.

@dhavaln
Last active September 1, 2024 23:14
Show Gist options
  • Save dhavaln/2fed8e1484d516e08a11a20cff795dba to your computer and use it in GitHub Desktop.
Save dhavaln/2fed8e1484d516e08a11a20cff795dba to your computer and use it in GitHub Desktop.
Setting up HAProxy on Mac OSX
global
log 127.0.0.1 local0
log 127.0.0.1 local1 debug
#log loghost local0 info
maxconn 4096
#chroot /usr/share/haproxy
#daemon
#debug
#quiet
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
timeout connect 5000
timeout client 50000
timeout server 50000
frontend localnodes
bind *:8000
mode http
default_backend nodes
backend nodes
mode http
balance roundrobin
option forwardfor
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
option httpchk HEAD / HTTP/1.1\r\nHost:localhost
server server1 192.168.1.135:3000 check
Install HAProxy from Homebre:
`brew install haproxy`
For full reference:
https://serversforhackers.com/load-balancing-with-haproxy
@cirocosta
Copy link

thx for the gist!

I needed to install from source and have Lua support to, so I wrote this quick article: https://ops.tips/blog/installing-haproxy-lua-macos/

I hope it helps!

@acidumirae
Copy link

acidumirae commented Sep 1, 2024

This config does not work with the current Homebrew formulae as of Sep 2024:

[ALERT] (58316) : config : Error(s) found in configuration file : /opt/homebrew/etc/haproxy.cfg
[ALERT] (58316) : config : Fatal errors found in configuration.
[NOTICE] (58317) : haproxy version is 3.0.3-95a607c
[ALERT] (58317) : config : parsing [/opt/homebrew/etc/haproxy.cfg:34] : 'option httpchk' : hiding headers or body at the end of the version string is unsupported.Use 'http-check send' directive instead..

The line 34 should expand into like

option httpchk
http-check connect port 3000
http-check send hdr host localhost meth GET uri /
http-check expect status 200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment