Apache proxy configuration (webapp resources URL truncated)
I'm trying to set up a proxy in an Apache web server but I have an issue about the build of URL beacause in the resulting URL part of the path is missing. An example:
http://server/webapp/style.css
(expected)
http://server/style.css
(real result)
I have a server exposed on the web (that I will call frontendserver) and another server (backendserver) in an internal network (non accessible from the web) where there is the web application that I want to proxy outside. I tried some methods and the main issue is that in the proxy the URL is not (re)-written in the right way, the server or browser miss a part.
What I tried:
ProxyPass /webapp http://backendserver
ProxyPassReverse /webapp http://backendserver
The URL of the app in the browser is correct http://frontendserver/webapp
; the index.html is visible but all the annexed resources (js, sockets, css, etc.) are missing because their URLs are http://frontendserver/style.css
instead of http://frontendserver/webapp/style.css
.
Is this the right method to set up this type of proxy properly?
I have tried some other solution also with the Apache rewrite module but I do not reach a good result, maybe someone have a good suggestion to solve the issue.
Thanks
ProxyPass
changes how URLs are answered, but it doesn't rewrite the URLs in your index.html. To fix that problem, your options are:
-
Rewrite index.html to use relative links (
css/style.css
) instead of absolute (/css/style.css
), so they still work from a different URL base. -
Use mod_proxy_html to rewrite the links in your outgoing HTML, Javascript, and CSS content. Something like:
<Files *.html> ProxyHTMLEnable On ProxyHTMLLinks a href ... ProxyHTMLURLMap http://frontendserver/ http://frontendserver/webapp/ </Files>
The first solution is best if you can easily do it, since it makes your content portable and is more reliable.
The second solution may work for you, if all of the URLs in your content are static. But mod_proxy_html doesn't know anything about dynamically calculated URLs - for example, if you calculate URLs in Javascript. So it that case it will fail unless you also revise your code to use a dynamic URL base.