Hi,
I am currently trying to replace our nginx, that we only use for proxying.
I am currently working on our first application and got it almost working. The only problem is the path of the url:
The setup is as follows:
all our services run on subdomains
the applications themselves run on different servers with a path to them e.g.
should be mapped to
I managed to get it working with the given configuration to work completely with
but i struggle to remove the /app1 from the client after a call.
in nginx the config was simply a proxy_pass https://backend/app1
but i do not seem to get the rewrite right for haproxy
btw the version that i am runnning is 2.6 and i removed the letsencrypt part from here since that seems to be working fine and does not interfere with the problem i am trying to solve
the config looks as follows:
global
log /dev/log local0
log /dev/log local1 debug
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
defaults http_defaults
log global
mode http
option httplog
option dontlognull
option forwardfor
timeout connect 50000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
frontend app1 from http_defaults
bind :443 ssl crt /etc/ssl/letsencrypt
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
http-request add-header X-Forwarded-For %[src]
http-request add-header X-Real-Ip %[src]
acl cond_is_app1 hdr(Host) app1.example.com
# set headers
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
http-request add-header X-Forwarded-For %[src]
http-request add-header X-Real-Ip %[src]
acl cond_is_favicon path -i /favicon.ico
acl cond_is_robot path -i /robots.txt
acl cond_is_resources path_beg /resources
use_backend hosted if cond_is_favicon || cond_is_robot || cond_is_resources
# i tried this one but it did not help
# acl is_path_app1_set path_beg /app1
# http-request set-path %[path,regsub(^/app1/,/)] if is_path_app1_set
use_backend %[req.hdr(Host),lower] if cond_is_app1
backend app1.example.com from http_defaults
option accept-invalid-http-response
balance roundrobin
cookie SERVER insert indirect nocache
http-request set-header Host app1.example.com
acl is_path_app1_set path_beg /app1
http-request replace-uri ([^/:]*://[^/]*)?(.*) \1/app1\2 if !is_path_app1_set
server app-1 1.1.1.1:443 ssl check verify none cookie app-1
backend hosted from http_defaults
option forwardfor
http-request set-header Host hosteddata.otherservice.org
http-request replace-uri ([^/:]*://[^/]*)?(.*) \1/stuff\2
server resources hosteddata.otherservice.org ssl verify none