How to configure mod_proxy_html with mod_proxy_balancer to resolve relative URLs

346 views Asked by At

I'm trying to configure mod_proxy_html such that my pages can resolve relative URLs. Apache runs normally with my config, but relative URLs are not resolved.

.conf file

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    ProxyHTMLEnable On

    Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
    <Proxy balancer://mycluster>
            BalancerMember "http://localhost:8080"
            BalancerMember "http://localhost:8180"
            ProxySet stickysession=ROUTEID
    </Proxy>
    ProxyPass / balancer://mycluster
    ProxyHTMLURLMap / balancer://mycluster
    RequestHeader    unset  Accept-Encoding
</VirtualHost>

Result accessing jboss directly:

enter image description here

Result accessing jboss through apache's mod_proxy load balancing:

enter image description here

Evidently, no static resources are loaded in the latter due to this problem.

1

There are 1 answers

0
Eric Freitas On

I had to configure "ProxyPassReverse" and "ProxyHTMLURLMap", and a trailing slash was needed at the end of the configured URLs. My configuration ended up like this:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
    <Proxy balancer://mycluster/>
            BalancerMember "http://localhost:8080"
            BalancerMember "http://localhost:8180"
            ProxySet stickysession=ROUTEID
    </Proxy>
    ProxyPreserveHost On
    ProxyPass / balancer://mycluster/ 
    ProxyPassReverse / balancer://mycluster/ 
    ProxyHTMLURLMap balancer://mycluster/ /
    SetOutputFilter  proxy-html
    RequestHeader    unset  Accept-Encoding

</VirtualHost>