HAProxy – Redirect a connection to an external server but maintain the URL in browser

Brad R asked:

We’re int he process of migrating from nginx to HAProxy and one of my redirects needs to point a certain URL to an external server, but we also need to maintain that original URL in the address bar. I’ve tried numerous things with http-request and https-response, but I always end up showing the external site in the browser.

The below config is working in nginx for the wanted behavior. Can anyone help me out with my backend in HAProxy to mimic this result?

                proxy_pass https://<site>/;
                sub_filter_once off;
                sub_filter '<external_site>' '<my_site>';
                sub_filter_types text/html application/json application/xhtml+xml application/xml application/x-javascript;
                proxy_set_header Host <external_site>;
                proxy_set_header Accept "";
                proxy_set_header Accept-Encoding "";
                proxy_redirect <external_site> <my_site>;
                proxy_intercept_errors on;
        }```

My answer:


HAProxy does not provide any functionality to alter HTTP response bodies. It is not really a web server, either, but a load balancer. If you need this functionality you should continue to use nginx.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.