21

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!

mohrphium
  • 615
  • 2
  • 9
  • 16

3 Answers3

43

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
Piotr
  • 579
  • 5
  • 3
3

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>
HBruijn
  • 72,524
  • 21
  • 127
  • 192
2

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
grafzero
  • 19
  • 2