Apache – Proxy HTTP Redirect to IP and Set Hostname

apache-2.2hostnamehttp-headersreverse-proxy

hopefully you guys can help me with a proxy problem I have.

What I already have

I have set up an apache http reverse proxy, to proxy requests from *.proxy.domain to *.intern.domain. The apache is the only way to reach my internal webapplications from an external network.

Example:

app.proxy.domain -> app.intern.domain
mail.proxy.domain -> mail.intern.domain

This is all working great, but I have the following problem.

Problem
I want to proxy the following requests:

app.proxy.domain -> app.internal.domain
app-dev.proxy.domain -> app-dev.internal.domain

This is no problem, but unfortunately the app-dev server runs an exact copy of the app servers webapplication, and this webapplication only responses to it's hostname (app.intern.domain)

So what I need to do is proxy the following

app.proxy.domain -> app.internal.domain (10.0.1.1)
app-dev.proxy.domain -> app.internal.domain (10.0.1.2)

I can do the second thing, by adding "10.0.1.2 app.internal.domain" in /etc/hosts, but that also means that app.proxy.domain will land on the dev-server.

I am searching for an option, to set the /etc/hosts entry only inside the vhost configuration file for app-dev.proxy.domain, so that every other vhost config will just use DNS for app.intern.domain.

Thoughts…

Is there a way to tell apache config, to

ProxyPass / http://10.0.1.2/

but send app.intern.domain as hostname?

Editing the dev-servers webapplication to listen to app-dev is no option, since it is supposed to be an exact copy (not my decision…)

Thanks!

Best Answer

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