Search code examples
tomcathaproxy

How do I configure Tomcat HAProxy to forward from localhost:8080/path to 1.2.3.4:8080/path?


All the HAProxy tutorials give examples only about port 80 and some default path. How do I configure Tomcat HAProxy to forward from localhost:8080/path to 1.2.3.4:8080/path? I can't figure it out in the config file


Solution

  • Assuming you want to proxy all requests coming to /path to 1.2.3.4:8080/path, you could do something like this:

    frontend http_fe
        bind *:443
        option forwardfor
        use_backend be_path if { path_beg /path }
        default_backend default_be
    
    backend be_default
        ...
    
    backend be_path
        mode http 
        option forwardfor
        server srv01 1.2.3.4:8080