Search code examples
devopshaproxywebmin

Using A Path Rewrite / Redirect In HA Proxy


I am using HA Proxy, I have a path redirect set and that works, the path redirects to webmin but it does not load any css and when submitting the login, its to the domain and not the path like it should be.

I am not sure if this is an Ha Proxy issue or not, maybe a config option in webmin to make it run from a folder / path?

This is my config for Ha Proxy

frontend public
    # Listen on ports 80 and 443
    bind *:80
    # bind *:443 ssl crt /xxxxx

    mode http

    # Define ACLs for each domain
    acl admin url_beg  /webmin
    #acl admin path_beg -i /webmin

    # Figure out which backend (= VM) to use
    use_backend webmin if admin

backend webmin
    #http-request set-path %[path,regsub(^/webmin/,/)]
    #http-request set-path /webmin/%[path]
    #http-request replace-uri ([^/:]*://[^/]*)?(.*) \1/webmin\2 if !remove_webmin
    #http-request set-header X-Forwarded-Port %[dst_port]
    #http-request add-header X-Forwarded-Proto https if { ssl_fc }
    http-request set-header Host xxxx/webmin
    #http-response replace-value Location (.*):.* \1/webmin
    #rspadd Strict-Transport-Security:\ max-age=15768000;\ includeSubDomains
    #rspadd X-XSS-Protection:\ 1;\ mode=block

    http-request set-path %[path,regsub(^/webmin/,/)]
    #http-request set-path /webmin/

    http-request set-header Host %[src]
    http-request set-header X-Forwarded-For %[src]
    http-request set-header X-Forwarded-Port %[dst_port]
    http-request set-header Connection "keep-alive"

    #acl missing_slash path_reg ^/webmin/[^/]*$
    #http-request redirect code 301 prefix /webmin drop-query append-slash if missing_slash

    #balance leastconn
    #option httpclose
    #option forwardfor
    #cookie JSESSIONID prefix

    # Redirect To Webmin
    server webadmin 127.0.0.1:10000 check

Any help is most welcome,

Thanks,


Solution

  • So I have a working solution here, its not just about ha proxy but you have to set a preix path in webmin as well.

    Sidenote, maybe dont use 'webmin' as the folder / path redirect. As the webmin configuation settings seem to use that path, so you end up with 'webmin/webmin'

    HA Proxy Config

    frontend public
      # Listen on ports 80 and 443
      bind *:80
      # bind *:443 ssl crt xxxxx
    
      mode http
    
      # Define ACLs for each domain
      acl admin url_beg  /webmin
      #acl app hdr(host) -i xxxxx.com
    
      use_backend webmin if admin
    
    backend webmin
      http-request set-header Host DONAME-NAME-HERE/webmin
      http-request set-path %[path,regsub(^/webmin/,/)]
      http-request set-header X-Forwarded-For %[src]
      http-request set-header X-Forwarded-Port %[dst_port]
      http-request set-header Connection "keep-alive"
    
      http-response set-header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
      http-response set-header X-Frame-Options SAMEORIGIN
      http-response set-header X-XSS-Protection "1; mode=block"
    
      balance leastconn
      option httpclose
      option forwardfor
      cookie JSESSIONID prefix
    
      http-response replace-value Location (.*):.* \1/
    
      # Redirect To Webmin
      server webadmin 127.0.0.1:10000 check
    

    Webmin Config file

    referer=xxxx/webmin/
    host=xxx/webmin/
    webprefix=/webmin
    webprefixnoredir=1