Use environment variables in Apache proxy (ProxyPass & ProxyPassReverse) 


September 22, 2014 22:23:25    Last update: September 22, 2014 20:33:52
Environment variables can be used in Apache ProxyPass and ProxyPassReverse directives. This example shows how to use mod_rewrite to set an environment variable, then use it in ProxyPassReverse.
# turn on interpolation
ProxyPassInterpolateEnv On

# set env variable with mod_rewrite
RewriteEngine on
RewriteMap lowercase int:tolower

# Set the SERVER_NAME env variable
RewriteRule ^ - [E=SERVER_NAME:${lowercase:%{SERVER_NAME}}]

# preserve host name
ProxyPreserveHost On

# use it
ProxyPass /path-to-be-proxied http://my.backend.server
ProxyPassReverse /path-to-be-proxied http://${SERVER_NAME} interpolate

Apache will give a warning about SERVER_NAME not defined, but you can safely ignore it.
Share |
| Comment  | Tags