The problem is that im getting redirected to the CDN-URL. Is there any way to get the content of the file without the URL redirection? Thanks in advance
I’m not sure I understand exactly what you’re trying to do. The first thing to note, however, is that the X-Fowarded-For header is typically used to send the IP address along of the original client (since in a proxyed world, those addresses would be hidden). Additionally, HAProxy is not really a web server in the traditional sense, so there’s no way to ‘get the content of the file’ directly from HAProxy, as I understand your request.
In any case, I think what you want is something more like this - this config is not a complete config:
frontend http-in
option forwardfor
use_backend api if { path_beg /api }
use_backend cdn if { path_end /index.html }
default_backend cdn
backend api
server s1 <ip of api server>
backend cdn
server s1 <ip of cdn>
Maybe I didn’t explain myself clearly with the “get the contents from the file”. What I’m trying to do is a redirect to CDN & rewrite the URI in order to get the file from the CDN with the initial url
I believe this is the correct way to perform a redirect
Okay - thanks for the explanation. It makes more sense now. Maybe something like:
frontend http-in
acl host_client hdr(host) -i mydomain.com
http-request redirect code 301 location https://cdn/static/site/index.html if host_client
default_backend api
backend api
...foo
And if you need to more dynamically set the URL for the CDN, you could do that too:
http-request redirect code 301 location https://cdn/static/%[hdr(host)]/index.html if host_client
…or something like that. I would say it’s better to explicitly redirect away from HAProxy in the frontend, rather than trying to coerce a backend into doing what you want.
I think there’s a lot of context that I don’t have on your config. Can you post the whole config? Can you be more specific about which routes should go where?
frontend www-http
bind *:80
redirect scheme https code 301 if !{ ssl_fc }
default_backend api
frontend www-https
bind *:443 ssl crt /home/certs/cert.pem
acl host_client hdr(host) -i <mydomain.com>
http-request set-path /static/foo/bar<put client specific things here> if host_client
use_backend cdn if host_client
default_backend api
backend api
cookie SERVERID insert indirect nocache
server web1 <server ip> check cookie web1
backend cdn
server s1 https://cdn/
The idea here is that if it is a specific domain ‘mydomain.com’, we will fetch all requests from the CDN. We will also modify the path to reflect the CDN url. Then we send it to a CDN specific backend.
Otherwise, we consider it an api request and let it go.