Skip to content

Instantly share code, notes, and snippets.

@juanpabloaj
Created May 4, 2020 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpabloaj/d840f3835652115f833a9a550bc798e5 to your computer and use it in GitHub Desktop.
Save juanpabloaj/d840f3835652115f833a9a550bc798e5 to your computer and use it in GitHub Desktop.
haproxy strip path prefix
docker-compose build --no-cache haproxy && docker-compose up -d
$ curl 0.0.0.0:8080/echob/metrics
hello from service b
$ curl 0.0.0.0:8080/echoa/metrics
hello from service a
version: "3.3"
services:
service-a:
image: hashicorp/http-echo
command: -text="hello from service a"
service-b:
image: hashicorp/http-echo
command: -text="hello from service b"
haproxy:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
depends_on:
- service-a
- service-b
FROM haproxy:1.7
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
defaults
log global
retries 3
maxconn 2000
timeout connect 5s
timeout client 50s
timeout server 50s
frontend services-echo
mode http
bind :8080
acl echoa_path path_beg /echoa
acl echob_path path_beg /echob
use_backend echoa if echoa_path
use_backend echob if echob_path
backend echoa
mode http
reqrep ^([^\ ]*\ /)echoa[/]?(.*) \1\2
server service-a service-a:5678
backend echob
mode http
reqrep ^([^\ ]*\ /)echob[/]?(.*) \1\2
server service-b service-b:5678
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment