Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Hope you can help me with this one, I have an apache server configured as a reverse proxy for some domains. They point to and iis server and also have some php sites as virtualhost in the same machine.

For the reverse proxy I did this:

<VirtualHost *:80>
    ServerName reverseprox1
    ServerAlias site1.domain.com
    ProxyRequests Off
    ProxyPass / http://site1.domain.com/
    ProxyPassReverse / http://site1.iisserver.internald.com/
    ProxyPassReverseCookieDomain site1.iisserver.internald.com site1.domain.com
<VirtualHost *:80>
    ServerName reverseprox2
    ServerAlias site2.domain.com
    ProxyRequests Off
    ProxyPass / http://site2.domain.com/
    ProxyPassReverse / http://site2.iisserver.internald.com/
    ProxyPassReverseCookieDomain site2.iisserver.internald.com site2.domain.com

Works fine, but now i need to add about 20 testing sites (with random names, not only site1,site2,site3, etc) pointing to the iis server. Is there a way to make this dynamic? I.E. It detects the site2 of site2.domain.com and point it to site2.iisserver.internald.com.

I can not use squid.

Here is my try, but failing miserably so far

<VirtualHost *:80>
    ServerName default
    ServerAlias  domain.com
    ProxyRequests Off
    RewriteEngine on
    RewriteCond %{HTTP_HOST} (.+)\.domain\.com
    ProxyPass / http://%1.domain.com/
    ProxyPassReverse / http://%1.iisserver.internald.com/
    ProxyPassReverseCookieDomain %1.iisserver.internald.com %1.domain.com

Thanks very much for your help

share|improve this question

2 Answers 2

What's wrong with a two liner like:


w[[  $(( $i < 21 )) != 0 ]]
  cat << EOF
  <VirtualHost *:80>
    ServerName reverseprox$i
    ServerAlias site$i.domain.com
    ProxyRequests Off
    ProxyPass / http://site$i.domain.com/
    ProxyPassReverse / http://site$i.iisserver.internald.com/
    ProxyPassReverseCookieDomain site$i.iisserver.internald.com site$i.domain.com
  i=$(( $i + 1 ))

It prints all the records you need to add to you conf file.

share|improve this answer
Sorry, I wasn't clear. The name of the site could be anything (not site[N]) I just put as an example. abc.domain.com, hello.domain.com, etc. thanks for you help –  tmp Oct 14 '11 at 15:48
If you have a (fairly static) list of the "anything", what above still applies. If not this url (cmdln.org/2008/06/10/…) may be your uncle. –  Alien Life Form Oct 14 '11 at 15:58

I'm pretty sure you can use re-write rules for this.

See http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p for a description of how to set a rewrite rule to use mod_proxy.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.