Search code examples
apachereverse-proxyproxypass

Apache: Reverse Proxy based on subdomain


I'm trying to set a reverse proxy by replacing the domain and keeping the subdomain. What I want to achieve is:

  • abc.example.org shall be reverse proxied to abc.hello.dev
  • xyz.example.org shall be reverse-proxied to xyz.hello.dev

Note: abc, xyz, etc. are completely dynamic.

What I'm currently not getting is the syntax for ProxyPass and ProxyPassReverse.

Thank you very much,

Cheers Fritz


Solution

  • Found the solution:

    <IfModule mod_proxy.c>
      SetEnvIf Host "^([^.]*).example.org$" SUBDOMAIN=$1
      ProxyPassInterpolateEnv On
      ProxyPass / https://${SUBDOMAIN}.hello.dev/ interpolate
      ProxyPassReverse / https://${SUBDOMAIN}.hello.dev/ interpolate
     </IfModule>