Backend by dns and not by ip


#1

Hello,

I have 2 servers: server_1 and server_2 where server_2 is a virtual machine that to access it I have to access by sub.domain.com because if I use the ip I will be accessing the main machine.

I have configured that server_1 uses the ip and server_2 use the option redir.

server server_1 10.0.0.1:80 check
server server_2 10.0.0.1:80 check redir http://sub.domain.com

Now I have a problem, when using server_2 my application gives problems with Access-Control-Allow-Origin. From what I’ve added in the frontend
http-response add-header Access-Control-Allow-Origin% [capture.req.hdr (0)] if {capture.req.hdr (0) -m found}

But when you add that line, it gives problems to my server_1, since Access-Control-Allow-Origin is duplicated

How can I configure that when accessing server_1, do not add Access-Control-Allow-Origin and when you access server_2, add it?

Or how can I do to not use the redirect option and when using server_2 use the domain name and not its ip?


#2

Thats not at all what the redir option is for. The redir option is causing a redirect to sub.domain.com, however what you seem to need is to rewrite the Host header.

In the backend, set the Host header. server_1 does not care and server_2 will expect it:
http-request set-header Host sub.domain.com