0

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.

2 Answers 2

1

I found the ProxyHTMLURLMap directive lacked the flexibility I needed with the substitutions. Instead I used the Substitute directive.

To ensure the substitutions occurred in each of the file types I cared about, I first used the following directive:

     AddOutputFilterByType SUBSTITUTE text/javascript text/html text/css

Then I used many Substitute directives. An example of one of those is:

    # Fixup min.js urlPath() references
    Substitute "s#(urlPath\(\))#$1 + \"$npar/\" #q"

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:

    Substitute "s#(\"|\')/(api|app|images|source|style)#$1/$npar/$2#q"

If you have a big file, and lots of individual Substitute directives, then the performance penalty is significant!

Matt.

0

One down, one to go. I discovered the fix for one of my questions, duplicate substitutions... In brief, this is bad:

ProxyHTMLEnable On
SetOutputFilter INFLATE;proxy-html;DEFLATE

Both directives insert proxy-html filter provider into the Output Filter chain. Apparently, at one time, ProxyHTMLEnable did not insert proxy-html, so the second line was needed.

No more duplicates, once I corrected the 2nd line to be:

ProxyHTMLEnable On
SetOutputFilter INFLATE;DEFLATE

For completeness, an equivalent would be:

ProxyHTMLEnable Off
SetOutputFilter INFLATE;proxy-html;DEFLATE

Matt.

2
  • Did you solve the 2nd problem? Jan 14, 2019 at 18:20
  • Yes I did. I added that content in a separate answer. Jan 15, 2019 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.