0

i configure haproxy, when i type test.example.com it redirect me to example.com/test

This is what i want but the problem i want this happen without changing the url on the browser, i want it to keep test.example.com but send request to example.com/test

Here is my haproxy.cfg

**frontend tt bind *:80 bind *:443 mode http default_backend ss bind :443 ssl crt /etc/ssl/certs/ssl.pem

 http-request redirect scheme https unless { ssl_fc } 

backend ss 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 } http-request set-var(req.rewrite_example) req.hdr(host),lower,regsub(.example.com$,) if { hdr_end(host) -i .example.com } http-request set-path /%[var(req.rewrite_example)] if { var(req.rewrite_example) -m found }

http-request set-header Host example.com if { var(req.rewrite_example) -m found } option httpchk HEAD / HTTP/1.1rnHost:localhost

server web1 example.com:80

**

1 Answer 1

0

Your configuration is almost working, please check the below few changes:

# ## example_fe ##
frontend example_fe
    bind *:80 
    bind *:443 ssl crt /etc/ssl/certs/ssl.pem
    http-request redirect scheme https unless { ssl_fc } 
    mode http 
    default_backend example_be
# ## example_be ##
backend example_be
    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 } 
    http-request set-var(req.rewrite_example) req.hdr(host),lower,regsub(\.example\.com$,) if { hdr_end(host) -i .example.com } 
    http-request set-path /%[var(req.rewrite_example)]%[path] if { var(req.rewrite_example) -m found }
    http-request set-header Host example.com if { var(req.rewrite_example) -m found } 
    server web1 172.17.1.1:80
     

I have tested it on HAProxy version 2.4 and it works just fine. The above config is driven from Michael: https://serverfault.com/a/815668/372988

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .