I'm trying to set up an apache server for test purposes. The goal is to simulate a loadbalancer. The part we're trying to simulate is simply accepting a clients secure httprequest and pass it on (via unsecure http) to the correct server using proxypass. This all works 100%.
The problem is this: I want to use this "load balancer" for several development environments. To be able to test the server-side of the applications, I want proxypass to use a variable URL to pass to, being the clients IP. This will require using a variable URL in the proxypass rule. I've found the variable REMOTE_ADDR, but I cannot seem to use this in the proxypass rule. I first tried the syntax that the apache website told me to use, but that didnt work (getting a DNS lookup failure for http://REMOTE_ADDR/foobar/). I know I have to do something with Interpolate, but I cannot seem to figure out what exactly that would be.
This line does what it should do, so the server works great:
ProxyPass / http://localhost:81/
These are the rules I've tried (using the variable) which failed.
ProxyPass / http://${REMOTE_ADDR}:81/
Error: [client 127.0.0.1] proxy: DNS lookup failure for: ${remote_addr} returned by /
ProxyPass / https://%{REMOTE_ADDR}s/
Error: [client 127.0.0.1] proxy: DNS lookup failure for: %{remote_addr}s returned by /
ProxyPassInterpolateEnv On
...
ProxyPass / http://${REMOTE_ADDR}:81/ interpolate
Error: [client 127.0.0.1] error parsing URL //:81: Invalid host/port
Anyone any idea's?
For the interpolate case, it's supposed to be like this:
RewriteEngine on
RewriteMap lowercase int:tolower
#This sets the variable to env:
RewriteRule ^ - [E=SERVER_NAME:${lowercase:%{SERVER_NAME}}]
#Now interpolate makes variables available for proxypass & proxypassreverse:
ProxyPassInterpolateEnv On
ProxyPass / ajp://${SERVER_NAME}:8009/ interpolate
ProxyPassReverse / ajp://${SERVER_NAME}:8009/ interpolate
After searching all night on the Internet, I couldn't find any clear cases like this or any answers. I finally figured it out, though.
You can replace Proxypass instructions by mod_rewrite rules with the [P] code, P means proxy.
Mod_rewrite will let you do more specific things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With