Apache HTML reverse proxy how to resolve bad links

1

I'm using Apache 2.4 reverse proxy to get remote access to my webcams. The reverse proxy is working fine.

  • External URL: http://example.com/camera1/home.asp
  • Internal URL: http://camera1/home.asp

However some links starting with /—absolute URI from site root and not relative URI—are not correctly rewritten by the reverse proxy.

Instead of being rewritten like this:

http://example.com/camera1/script.js

They are rewritten like:

http://example.com/script.js

Which is preventing the application to work properly. This is simply because Apache is not able to identify the link I'm using mod_proxy, mod_proxy_http, mod_proxy_html.

The automatic rewriting of the links provided by mod_proxy_html for HTML, CSS can not work in this context because the missed links are inside a minified JavaScript (compacted with no space and no indentation)

There is no need to say I can't modify the software of my webcams.

However, I have identified patterns which I could apply to make the correction if I would know how to introduce a regex to be applied before sending the reply back to the client.

Is there any way to apply some post processing to the application answer?

My config looks like this:

ProxyRequests Off
ProxyPass /cam1/ http://cam1/
ProxyPassReverse /cam1/ http://cam1/
<Location /cam1/>
    ProxyHTMLEnable On
    ProxyHTMLExtended On 
    ProxyHTMLURLMap /cgi/ /cam1/cgi/
    ProxyHTMLURLMap /advanced_data.asp /cam1/advanced_data.asp
</Location>

It is working fine for most of the situations, the response is correctly processed, I can see /cam1 which is added. But some scripts are not working.

nico

Posted 2019-04-08T14:58:28.650

Reputation: 11

What does your Apache reverse proxy config look like? Look at my general answer here on setting up an Apache reverse proxy for possible tips and ideas. But in general you might do some research on mod_rewrite specifically RewriteMap and RewriteRule. Those options allow you to create regex for filtering URLs just the way you describe.

– JakeGould – 2019-04-08T15:09:31.160

I have added my reverse proxy configuration in my question<br>. If I'm correct the rewrite module is processing URLs only, not the response content – nico – 2019-04-08T23:23:17.960

Thanks for adding! Should help others if I cannot look at out later when I have time. But please do not use HTML or HTML entities in your posts here. Please read up on how this site use Markdown to format posts; utterly no need to add any of the HTML you have added.

– JakeGould – 2019-04-08T23:49:52.077

Answers

0


I needed a way to replace one regexp by another in the response flow. I found all I needed there : mod_sed
This requires to add the mod_sed module to Apache configuration.
LoadModule sed_module modules/mod_sed.so
So I can apply a sed command to the response flow.
I added theses lines to my original configuration: AddOutputFilter Sed js OutputSed "s/\"\/cgi\//\"\/cam1\/cgi\//g" So the lines which are not corrected automatically by the ProxyHTMLURLMap instruction, are corrected by the sed instruction.

This is giving finally: ProxyPass /cam1/ http://cam1/ ProxyPassReverse /cam1/ http://cam1/ <Location /cam1/> ProxyHTMLEnable On ProxyHTMLExtended On ProxyHTMLURLMap /cgi/ /cam1/cgi/ ProxyHTMLURLMap /advanced_data.asp /cam1/advanced_data.asp AddOutputFilter Sed js OutputSed "s/\"\/cgi\//\"\/cam1\/cgi\//g" </Location>

nico

Posted 2019-04-08T14:58:28.650

Reputation: 11