Skip to content

Instantly share code, notes, and snippets.

@bhameyie
Last active November 28, 2023 22:30
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save bhameyie/07c1ee9aaa3e8a200c8c to your computer and use it in GitHub Desktop.
Save bhameyie/07c1ee9aaa3e8a200c8c to your computer and use it in GitHub Desktop.
Sample haproxy config
##based on Mesosphere Marathon's servicerouter.py haproxy config
global
daemon
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
tune.ssl.default-dh-param 2048
defaults
log global
retries 3
maxconn 2000
timeout connect 5s
timeout client 50s
timeout server 50s
listen stats
bind 127.0.0.1:9090
balance
mode http
stats enable
stats auth admin:admin
frontend microservice_http_in
bind *:80
mode http
frontend microservice_http_appid_in
bind *:81
mode http
acl app__accountCreationService hdr(x-microservice-app-id) -i /accountCreationService
acl app__profileEditingService hdr(x-microservice-app-id) -i /profileEditingService
use_backend accountCreationService_10000 if app__accountCreationService
use_backend profileEditingService_20000 if app__profileEditingService
frontend microservice_https_in
bind *:443 ssl crt /etc/ssl/yourCertificate
mode http
frontend accountCreationService_10000
bind *:10000
mode http
use_backend accountCreationService_10000
frontend profileEditingService_20000
bind *:20000
mode http
use_backend profileEditingService_20000
backend profileEditingService_20000
balance roundrobin
mode http
option forwardfor
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
server 151_256_250_152_35900 151.256.250.152:35900
# additional servers here
backend accountCreationService_10000
balance roundrobin
mode http
option forwardfor
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
server 101_206_200_192_31900 101.206.200.192:31900
# additional servers here
@KJSui
Copy link

KJSui commented Jan 18, 2018

Is this haproxy1.8 version?

@Helwieahmad
Copy link

can you give comment in right or below code for explain code by code? thanks in advance

@kennyparsons
Copy link

Thanks for the example! I'm a noob here, but what I'm trying to do is log all my own traffic at home by using HAProxy (the traffic is all coming through my VPN. I want to be able to see the traffic coming through.) How would I configure HA proxy to just pass all traffic through from the VPN to the destination and log it?

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