Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been setting up Amazon EC2 instances for an upcoming project which will involve hosting multiple websites on multiple web servers. They are all micro instances, running Ubuntu Server 64bit.

Here's what I have so far:

  • Web Server -- Apache
  • Database Server -- MySQL
  • Development Server -- Apache & MySQL
  • File Server -- SVN & Bacula (backups are done to S3 buckets)

Currently there's only one Web server, but I've made an image of it, so once the project starts I can launch as many instances as I need and configure them individually.

Everything has been going smoothly, but I've hit some snags.

My problem is I'd like to run multiple web server instances, but with Amazon's restriction to 5 Elastic IP address, I know that won't be enough. I was researching how to host websites on multiple web servers from a single IP address and ran across mod_proxy for Apache. I haven't tried it yet, but I think that's what I need. I'd just like someone to confirm that I'm on the right track.

Has anyone used Apache with mod_proxy? Does it truly allow you to host multiple websites from multiple using a single IP address?

Assuming I'm on the right track here, all I should need is one Elastic IP address pointing to an EC2 instance running Apache, is that right?

share|improve this question
After more research and experimentation, it looks like I may not need to use an Apache proxy server after all. I'm going to award the correct answer to Bond, since his response was the most detailed and would probably be the most helpful if I was continuing on that path. – ks78 Mar 1 '11 at 17:36
up vote 1 down vote accepted

Hi what you asked is a very common situation where in applications may not be running on Gateway and they may be running on some server in LAN but to the world it appears it is coming from

I run 4 websites with Apaches mod proxy and at least 15 different services on these 4 different websites depend upon them.I do not have an experience of Amazon EC2 but Amazon EC2 uses Xen as its backend. Let us say the main machine which faces internet and has a public IP be called dom0 now read in the following terminology

Dom0  with IP (This will be our Server facing internet)
DomU1 with IP
DomU2 with IP
DomU3 with IP
DomU4 with IP

I am assuming you have a local dns on Dom0 (or some where in your network ) which knows the DomU IPs with names.(If not life will be difficult) then in apache2.conf ( httpd.conf on Fedora type systems)

NameVirtualHost *
    <VirtualHost *>
      ServerName mainserver
            DocumentRoot /var/www
      ProxyRequests Off
           <Proxy *>
     Order deny,allow
           Allow from all
         ProxyPass /domu1
         ProxyPass /domu2
         ProxyPass /domu3
         ProxyPass /domu4
         ProxyPassReverse /domu1
         ProxyPassReverse /domu2
         ProxyPassReverse /domu3
         ProxyPassReverse /domu4

This way is one way to achieve the things which you asked (how ever not very recommended) if you upgrade the server (i.e. Dom0) the update may over write apache2.conf or httpd.conf what ever be the case. So once you understand what the above entries mean (Check it for your requirements I have struggled a long time back with some thing similar you want hence I gave an easy solution but not recommended). Once you understand the above ProxyPass then create different Virtual Host configurations in sites-available directory if it is a Ubuntu/Debian system or in Red Hat based it will be still possible (you will have to search) I am showing you one so it helps you rest 4-5 you can make on your own
Call this /etc/apache2/sites-enabled/myinterna1.conf it looks as follows

<VirtualHost *:80 >

        ServerAdmin webmaster@localhost

        ProxyRequests off
        <Proxy *>
        Order deny,allow
        Allow from all
        ProxyPreserveHost On

        ProxyPass /
        ProxyPassReverse /

        ErrorLog /var/log/apache2/server1/server1_error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
        CustomLog /var/log/apache2/server1/server1_access.log combined
        CustomLog /var/log/apache2/server1/server1-resp_log resp
        LogFormat "%a %{X-Forwarded-For}i  %h %D %t %f %p %>s  %U %v" resp


The above virtualhost will be defined on Dom0 so that all requests are served from an internal server way it will work is some one on internet will type in their browser

Now this request reaches Dom0 and Apache Virtual Host on Dom0 checks the Proxy Configuration and finds that /domu1 is mapped to an internal server so it forwards that to the machine which actually has to serve.To the user on internet all this is hidden.

How ever one word of caution while doing so the Apache on Ubuntu system serves the virtual hosts in alphabetical name of vhost file (not server name I am referring to name of file like sorting.c the Apache virtual host file) (that is why there is a file 000-default) on Ubuntu systems so make sure that you have one host more than the number of websites you are to serve (which will serve as error page).This is a standard practise.

share|improve this answer

Why not run them all on the same IP address and use Apache virtual hosting (i.e. Host-header based virtual hosting) to have the web server select the right site on a per-request basis?

That would only consume one IP address and Amazon's load balancing could do the rest.

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.