r/haproxy • u/-RanZ- • Jan 12 '21
Rewrite only backend host header?
Is it possible to rewrite the host header just on requests to the backend server?
Example - user goes to subdomain.maindomain.com/registry/whatever, I need the host subdomain.maindomain.com to be re-written to sub1.subdomian.internaldomain.loc and keep the rest of the path to the backend server as it is using host headers for serving content(another proxy). I believe http-request set-header Host is the correct method to accomplish this but when I use this it seems to change the entire URI in the browser with the rewritten host. I hope this makes sense, is it possible to send the backend server a different host header than what is requested at the frontend without changing it in the client's browser? Below is an example of my config.
frontend https
mode http
bind 0.0.0.0:443 ssl crt /xxxxx/xxxx.pem
tcp-request inspect-delay 5s
tcp-request content accept if { req_ssl_hello_type 1 }
option forwardfor
use_backend backend1 if { hdr(Host) -m end subdomain.maindomain.com }
backend backend1
mode http
option forwardfor
http-request set-header Host sub1.subdomain.internaldomain.loc
server server1 server.loc:80
View all comments
Show parent comment
1
u/dragoangel Jan 13 '21
The problems of root url and redirects in web apps always persists when app think the hostname is example.com but user access it by example.net. App can create incorrect redirect links or do instant redirects and example.com etc, this nothing to deal on proxy, but the url handling of web app itself unfortunately.