I currently have a vendor web application that puts fully qualified domain names in response bodies (HTML, JavaScript, CSS). For example, requests made to "realserver.mycompany.com" will contain JavaScript with variables that are set to https://realserver.mycompany.com/path/to/something. I have set up an apache server as a reverse proxy. The proxy directives don't have any effect on the response bodies, so I have included mod_substitute to find instances of "realserver.mycompany.com" and replace it with "proxyserver.mycompany.com". Although this works, it causes the browser client to create requests that contain "proxyserver.mycompany.com" as part of the data when the backend expects to see "realserver.mycompany.com". So I need to be able to perform the reverse substitution on request content that I'm performing on response bodies. However, the documentation for mod_substitute specifically states it operates on response bodies.
Here is the configuration I'm currently using:
<Location "/">
RequestHeader unset Accept-Encoding
RequestHeader unset Accept
RequestHeader set Accept-Encoding "identity; q=1.0,*;q=0"
ProxyPass https://realserver.mycompany.com/
ProxyPassReverse https://realserver.mycompany.com/
Substitute "s|realserver.mycompany.com|proxyserver.mycompany.com|in"
FilterDeclare webtestOut
FilterProvider webtestOut SUBSTITUTE "%{Content_Type} = ~m|^application/.*|"
FilterProvider webtestOut SUBSTITUTE "%{Content_Type} =~ m|^text/.*|"
</Location>
I can't figure out how to change instances of "proxyserver.mycompany.com" to "realserver.mycompany.com" before passing the request on to the back end server. I'm not tied to apache. If there's a way to accomplish this using NGINX, I'm happy to change.