Haproxy and fhem - How to path-redirect correctly


#1

I already asked this question at serverfault here (http://serverfault.com/questions/754236/haproxy-and-fhem-how-to-path-redirect-correctly), actually. Of course I will update both threads regularly.

I want to have the site www.url.at/ha redirected in the backend to 127.0.0.1:8083. The url should remain “www.url.at/ha” (or “www.url.at/ha/images/”… or “www.url.at/ha/?test=12”).

This works on most of my webinterfaces, but somehow or other there are problems with fhem. fhem uses a 302 redirect to /fhem if there is any request not targeting /fhem or /fhem/xxx/…

So I implemented a reqrep, which rewrites (1)/ha/(2) to (1)/fhem(2), resulting in getting shown the index file correctly (127.0.0.1:8083/fhem).

But: the images, js, css, etc. are trying to get www.url.at/fhem/images/

So the subsequent requests generated by (the source-code)? of the website links to the (wrong) main_server backend.

How can I achieve a correct redirection / reqrep for this specific case? I hope I have expressed myself in an understandable way… :wink:

My configuration:

frontend https-frontend
    bind *:443 ssl crt cert.pem
    default_backend main_server

    # Add missing slash if required...
    acl ms_ha path_reg ^\/ha[^\/]*$
    redirect code 301 prefix / drop-query append-slash if ms_ha

    acl is_ha       path_beg /ha/
    use_backend     be_ha if is_ha

backend main_server
        mode http
        server raspi-test 192.168.10.95:80

backend be_ha
        mode http
        reqrep ^([^\ ]*\ )/ha/(.*) \1fhem\2
        server ha-server 127.0.0.1:8083

#2

Anybody got an idea?
Thanks?


#3

The reason this post and the one on serverfault doesn’t spark huge interest is because the description is a mess. I’m sorry, but thats just the way it is.

Thats not an URL, thats just your backend IP and a port. What you are saying doesn’t make any sense.

So neither a redirect nor a rewrite?

So steer the /fhem/ traffic to the correct backend:

acl is_fhem       path_beg /fhem/
use_backend     be_ha if is_fhem

#4

Same as Lukas. I don’t have time to waste trying to understand what you mean.
If you want a quick and accurate answer, please ask an accurate question full of details.