Some haproxy config examples
Here are some config snippets from the haproxy setup I mentioned in the last post. Note that if this looks weird, it probably is - our environment is a bit of a mess, but due to constrained test resources, no cleanup is possible.
bind 192.168.0.50:80
# Subdomains: I put relevant subdomains here (just to keep track)
acl is_GKWEB-http hdr(host) -i -f /etc/haproxy/GKWEB-http-urls
# Subdomains: subdomain1 subdomain2
acl is_ITF01-http hdr(host) -i -f /etc/haproxy/ITF01-http-urls
# Subdomains: subdomain1 subdomain2
acl is_WEB34-IP2-http hdr(host) -i -f /etc/haproxy/WEB34-IP2-http-urls
# Subdomains: subdomain1 subdomain2
acl is_WEB02-IP2-http hdr(host) -i -f /etc/haproxy/WEB02-IP2-http-urls
use_backend GKWEB-http if is_GKWEB-http
use_backend ITF01-http if is_ITF01-http
use_backend WEB34-IP2-http if is_WEB34-IP2-http
use_backend WEB02-IP2-http if is_WEB02-IP2-http
default_backend maintenance
balance roundrobin
mode tcp
stick-table type ip size 200k expire 30m
stick on src
server lg01 192.168.1.51:22 check
balance roundrobin
# No persistence
server web02-ip2 192.168.1.92:80 check
backend WEB02-IP2-https
balance roundrobin
stick-table type ip size 200k expire 30m
stick on src
server web02-ip2 192.168.1.92:443 check ssl verify none
balance roundrobin
stick-table type ip size 200k expire 30m
stick on src
cookie SRV_ID prefix
server web03-ip4 192.168.1.64:80 check cookie
server web04-ip4 192.168.1.74:80 check cookie
backend WEB34-IP4-https
balance roundrobin
stick-table type ip size 200k expire 30m
stick on src
cookie SRV_ID prefix
server web03-ip4 192.168.1.64:443 check cookie ssl verify none
server web04-ip4 192.168.1.74:443 check cookie ssl verify none
Some organizational helpers I used:
- IP addresses 'make sense' - for example WEB02-IP2 is 192.168.1.62, -IP3 is .63, etc
- Keep the naming convention for backends consistent
- Keep things simple
- Comments only for the first frontend, first backend, unless actual specific notes required
- Keep spacing consistent, tabs, etc
Frontend Example
frontend domain1_com-httpbind 192.168.0.50:80
# Subdomains: I put relevant subdomains here (just to keep track)
acl is_GKWEB-http hdr(host) -i -f /etc/haproxy/GKWEB-http-urls
# Subdomains: subdomain1 subdomain2
acl is_ITF01-http hdr(host) -i -f /etc/haproxy/ITF01-http-urls
# Subdomains: subdomain1 subdomain2
acl is_WEB34-IP2-http hdr(host) -i -f /etc/haproxy/WEB34-IP2-http-urls
# Subdomains: subdomain1 subdomain2
acl is_WEB02-IP2-http hdr(host) -i -f /etc/haproxy/WEB02-IP2-http-urls
use_backend GKWEB-http if is_GKWEB-http
use_backend ITF01-http if is_ITF01-http
use_backend WEB34-IP2-http if is_WEB34-IP2-http
use_backend WEB02-IP2-http if is_WEB02-IP2-http
default_backend maintenance
SFTP Backend
backend LG01-sftpbalance roundrobin
mode tcp
stick-table type ip size 200k expire 30m
stick on src
server lg01 192.168.1.51:22 check
Backend with IP Session Persistence
backend WEB02-IP2-httpbalance roundrobin
# No persistence
server web02-ip2 192.168.1.92:80 check
backend WEB02-IP2-https
balance roundrobin
stick-table type ip size 200k expire 30m
stick on src
server web02-ip2 192.168.1.92:443 check ssl verify none
Backend with Cookie Session Persistence
backend WEB34-IP4-httpbalance roundrobin
stick-table type ip size 200k expire 30m
stick on src
cookie SRV_ID prefix
server web03-ip4 192.168.1.64:80 check cookie
server web04-ip4 192.168.1.74:80 check cookie
backend WEB34-IP4-https
balance roundrobin
stick-table type ip size 200k expire 30m
stick on src
cookie SRV_ID prefix
server web03-ip4 192.168.1.64:443 check cookie ssl verify none
server web04-ip4 192.168.1.74:443 check cookie ssl verify none
Comments
Post a Comment