0

I'm trying to hide a PWM registration page (whose URL is /pwm/public/newuser) behind the existing server http://customers.example.com, under the reserved path /register, so that pages like http://customers.example.com/, http://customers.example.com/shop, etc. would continue to work as usual, while http://customers.example.com/register is proxied to the PWM intranet installation.

PWM is deployed at "http://reg-server:8680/pwm.

Since that application relies on both HTML content (i.e. links and form action attributes) and javascript content referring to /pwm/... I had to manipulate both types of content content beside GET and POST requests and Location responses.

This is how I then configured Apache Httpd VirtualHost (more on the Header directives later):

<VirtualHost *:80>

    ServerName customers.example.com
    Header set Server "Apache"

    <Location "/public/api">

        Header append Server Funky

        <If "%{QUERY_STRING} =~ /processAction=clientData/">

            Header append Server Mojo

            AddOutputFilterByType SUBSTITUTE application/json

            Substitute s|url-context|url-ZZZ|
            Header append Server Tango

        </If>
    </Location>


    # ... ProxyPass directives

    <Location "/register">

    Header append Server "Apache-3"

    # HTML content proxy configuration #

    ProxyHTMLEnable On

    # Added proxying of 'meta' tag attributes
    ProxyHTMLLinks  meta       data-url-context content
    ProxyHTMLLinks  a          href
    ...
    ProxyHTMLLinks  script     src for

    ProxyHTMLDocType "<!DOCTYPE html>"

    ProxyHTMLCharsetOut *
    ProxyHTMLBufSize 16384
    ProxyHTMLExtended On
    SetOutputFilter INFLATE;proxy-html;DEFLATE

    # Replaced, but it seems it's not being used, page refresh is handled by js
    ProxyHTMLURLMap "(.*?)=/pwm/public/newuser(.*)" "$1=/register$2" RL

    ProxyHTMLURLMap "^/pwm$" "" RLn
    ProxyHTMLURLMap "/pwm/public/newuser" "/register" L
    ProxyHTMLURLMap "/public/newuser" "/register" L
    ProxyHTMLURLMap "/pwm" "" L
    ProxyHTMLURLMap "PWM_MAIN.submitPostAction('newuser', 'reset')" "PWM_MAIN.submitPostAction('registrazione', 'reset')" L

    </Location>

</VirtualHost>

The problem is that directive

Substitute s|url-context|url-ZZZ|

isn't being honored, because the call to

/public/api?processAction=clientData&etag=27...

yields the following JSON content:

{ ... "url-command":"/pwm/public/command","url-context":"/pwm","url-logout":"/pwm/public/logout", ... }

although the surrounding Header append ... ones are, because among server response headers I can see:

Server: Apache, Funky, Mojo, Tango

The issue arised when I enclosed the mod_proxy_html directives within <Location "/register"> and </Location> lines.

In fact, if I comment them out I can see:

{ ... "url-command":"/pwm/public/command","url-ZZZ":"/pwm","url-logout":"/pwm/public/logout", ... }

I'm new to Httpd, I don't see what's wrong with my configuration, I even tried specificng paths with regular expressions:

 <Location ~ "^/public/api">
 <Location ~ "^/register">

but nothing changed.

This happens with 2.4.33

0

The problem was that Httpd (I can't tell if that's by default or from an existing configuration) zips response bodies, so trying to apply any regular expression to compressed HTML wasn't matching anything (nor giving any error or hint about that).

In the former configuration, HTML content replacement was made possible by this directive:

SetOutputFilter INFLATE;proxy-html;DEFLATE

Of course after I moved all the mod_proxy_html directives inside <Location /> that SetOoutputfilter was no more active on the /public/api path.

So I reworded the <If> content like this:

<If "%{QUERY_STRING} =~ /processAction=clientData/">

    SetOutputFilter INFLATE;DEFLATE
    AddOutputFilterByType SUBSTITUTE application/json
    Substitute s|"(url-[^:]+)"\s*:\s*"/pwm(/?)([^,\}]*)"|"$1":"/$3"|q

</If>

and everything workend again — there's no HTML editing directive active on this location, so I left out the proxy-html filter.

The accepted answer to Apache Proxying leads to ERR_CONTENT_DECODING_FAILED error helped on that.

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.