Apache proxy_http redirect to ip and set hostname

Solution 1:

Possibly you could use mod_headers in conjunction with mod_proxy. I haven't tested it though.

So for your app-dev vhost you could have:

RequestHeader set Host "app.internal.domain"

and then you would add:

ProxyPreserveHost On

Solution 2:

Ugly work-around is to use (rather: abuse) the /etc/hosts to point app.internal.domain to localhost and then configure Apache to listen to two additional ports, one for each your app and app-dev. So Reverse proxy twice:

Listen 80
Listen 127.0.0.1:8001
Listen 127.0.0.1:8001

<VirtualHost *:80>
   ServerName app.proxy.domain
   ProxyPass / http://app.internal.domain:8001
</VirtualHost>
<VirtualHost *:80>
   ServerName app-dev.proxy.domain
   ProxyPass / http://app.internal.domain:8002
</VirtualHost>
<VirtualHost 127.0.0.1:8001>
   ServerName app.internal.domain
   ProxyPreserveHost On
   ProxyPass / http://10.0.1.1/
</VirtualHost>
<VirtualHost 127.0.0.1:8002>
   ServerName app.internal.domain
   ProxyPreserveHost On
   ProxyPass / http://10.0.1.2/
</VirtualHost>

Solution 3:

Add to reverse proxy's config (foe app-dev.proxy..):

RequestHeader edit Host ^app-dev.proxy.domain app.proxy.domain

You have to enable mod_headers beforehand:

a2enmod headers

Internal server 10.0.1.2 should has

ServerName app.proxy.domain