HAProxy – backend with subdirectory

directorydocumentroothaproxy

I have simple haproxy configuration: two servers, one is frontend, two is backend with jboss application. Here is config:

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000
frontend  proxy
    bind 192.168.2.1:443 ssl crt /etc/ssl/certs/certificate.pem
    default_backend             jboss
backend jboss
    #redirect scheme https if !{ ssl_fc }
    server      jboss 192.168.1.1:8080 check

I want to simplify url. Now if I want to enter to webapp I must type subdirectory in url https:// www.example.com/webapp/

I want to enter https:// www.example.com and haproxy will serve me page from http://192.168.1.1:8080/webapp.
How to do this?

Best Answer

Problem solved by adding redirect in frontend section.

frontend  proxy
    bind 192.168.2.1:443 ssl crt /etc/ssl/certs/certificate.pem
    acl path_root path /
    redirect location https://www.example.com/webapp/ if path_root
    default_backend             jboss