I'm using Apache 2.4.27 as a Reverse Proxy and I am having trouble with some of my ProxyHTMLURLMap directives.
I have a proxy-server and a backend server, called server1.
I have a JavaScript fragment appear in an HTML as well as a separate JS file. The ProxyHTMLURLMap incorrectly modifies the HTML file, and does not modify the JS file.
How do I define this URLMap to affect both places?
Here's my config fragment:
LogLevel warn proxy_html:trace3
<Location "/server1/">
ProxyPass https://server1:5443/ ping=2
ProxyPassReverse https://server1/
ProxyHTMLEnable On
ProxyHTMLExtended On
SetOutputFilter INFLATE;proxy-html;DEFLATE
ProxyHTMLURLMap /rpc/ /server1/rpc/
</Location>
The JavaScript fragment that appears in both HTML and JS files is:
abc.get({
url: "/rpc/getdefaultcfg.asp",
onrcv: function(arg) {
if (arg.STATUS == 0) {
default_Lang = WEBVAR_JSONVAR_GETDEFAULTLANG.WEBVAR_STRUCTNAME_GETDEFAULTLANG;
}
onload = loadInit();
}
});
The HTML file is modified by the ProxyServer twice by updating the matching line to:
url: "/server1/server1/rpc/getdefaultcfg.asp",
Notice the duplicate "server1". Why is it being duplicated?
This HTML file includes the JS file as follows:
<script language="Javascript" src="index.js"></script>
However, the index.js does not get modified by the proxy server. It remains untouched as:
url: "/rpc/getdefaultcfg.asp",
Why is the JS file untouched by the URLMap directive? Any ideas much appreciated!
FYI, the httpd_access_log file shows the 404 errors on line 2 and 5 below:
1. 192.1.0.76 - "GET /server1/index.html HTTP/1.1" 200 946
2. 192.1.0.76 - "GET /rpc/getdefaultcfg.asp HTTP/1.1" 404 223
3. 192.1.0.76 - "GET /server1/page/disable_javascript.html HTTP/1.1" 200 212
4. 192.1.0.76 - "GET /server1/page/blank.html HTTP/1.1" 200 -
5. 192.1.0.76 - "GET /server1/server1/rpc/getdefaultcfg.asp HTTP/1.1" 404 126
Finally, the output from proxy_html tracing:
[proxy_html:trace3] mod_proxy_html.c(265): [client 192.1.0.76:51880] C: matched /rpc/, substituting /server1/rpc/
[proxy_html:trace3] mod_proxy_html.c(265): [client 192.1.0.76:51880] C: matched /rpc/, substituting /server1/rpc/
[proxy_html:trace1] mod_proxy_html.c(827): [client 192.1.0.76:51880] Non-HTML content; not inserting proxy-html filter, referer: https://proxy-server/server1/page/header.html
[proxy_html:trace1] mod_proxy_html.c(827): [client 192.1.0.76:51880] Non-HTML content; not inserting proxy-html filter, referer: https://proxy-server/server1/page/header.html
[proxy_html:trace1] mod_proxy_html.c(827): [client 192.1.0.76:51892] Non-HTML content; not inserting proxy-html filter, referer: https://proxy-server/server1/page/login.html
[proxy_html:trace1] mod_proxy_html.c(827): [client 192.1.0.76:51892] Non-HTML content; not inserting proxy-html filter, referer: https://proxy-server/server1/page/login.html
[proxy_html:trace1] mod_proxy_html.c(827): [client 192.1.0.76:51880] Non-HTML content; not inserting proxy-html filter, referer: https://proxy-server/server1/page/header.html
[proxy_html:trace1] mod_proxy_html.c(827): [client 192.1.0.76:51880] Non-HTML content; not inserting proxy-html filter, referer: https://proxy-server/server1/page/header.html
Matt.
Best Answer
I found the
ProxyHTMLURLMap
directive lacked the flexibility I needed with the substitutions. Instead I used theSubstitute
directive.To ensure the substitutions occurred in each of the file types I cared about, I first used the following directive:
Then I used many
Substitute
directives. An example of one of those is:One thing to note is that the whole file is scanned for each
Substitute
directive, so try to cram as many substitutions as you can into one. For example, I used regex to cover several cases:If you have a big file, and lots of individual
Substitute
directives, then the performance penalty is significant!Matt.