How to replace domain in haproxy request?

is it possible to change/rewrite/replace the domain name in the request before you pass it through to the backend server?

I have 1 frontend:

frontend https-dev
        maxconn 2000
        option forwardfor header X-Real-IP
        http-request set-header X-Real-IP %[src]
        default_backend be-dev-cdn

        # BEGIN CORS
        http-response set-header Access-Control-Allow-Origin "*"
        http-response set-header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization, JSNLog-RequestId, activityId, applicationId, applicationUserId, channelId, senderId, sessionId"
        http-response set-header Access-Control-Max-Age 3628800
        http-response set-header Access-Control-Allow-Methods "GET, DELETE, OPTIONS, POST, PUT"
        # END CORS

        bind *:443 ssl crt domain.pem
        reqadd X-Forwarded-Proto:\ https
        # set X-SSL in case of ssl_fc <- explained below
        http-request set-header X-SSL %[ssl_fc]

And 1 backend with multiple hosts:

backend be-dev-cdn
        balance roundrobin
        server check
        server check
        server check
        server check
        server check

The user would input the domain and I would then rewrite/replace this domain to a new domain name based on the backend server to which the request is forwarded. For example: → haproxy → backend server; rewrite the request.

My goal is that I would just like to route the requests through haproxy server but not the response

Is this possible with haproxy?


In your backend section, you can add

http-request set-header Host

If needed you can add a condition, for example :

http-request set-header Host if { req.hdr(host) -i }


yes…this works if you are replacing 1 domain. If you look at my example I have configured 5 backend servers and would like to change the domain to the “domain” of the selected backend server.


selected backend server: change domain to
selected backend server: change domain to
selected  backend server: change domain to
selected backend server: change domain to
selected backend server: change domain to



I don’t know if it’s possible with different servers within the same backend. I mad some test (with : http-request set-header Host %s) and when Haproxy modify the headers, it seems it doesn’t know yet the server it will use.

Withe several backends named regarding the hos you want you can do

http-request set-header Host %b

Maybe with dynamic mapping but not very sure.

if you change the server name to match the domain you are sending it to, then you can use:

http-send-name-header  host

which will send the server’s “name” as the “Host” header.

1 Like

http-request set-header Host %b

That will set the host to the name of the backend, which is “be-dev-cdn”

%s will give you the servername, but I"m not sure if there is a way to get the hostname of the server line.

That’s why a said he has to rename backend.

But i was not aware of the http-send-name-header option. This seems the right way to do it.