Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Long time reader first time poster (he he). So here's my dilemma. I'm hosting 3 sites at home for some friends, nothing big, all just wordpress sites. Running them in VMWare Workstation. Got a ton of ram to spare and all that mess so no worries on the resource front. As I'm building site # 2, I realize, 'CRAP!... How am I going to route these in passed the router?" Now, before some of you say vhosts, I'm segregating the sites on different VM's. 1 of 3 is not a very important site, but in the event of something, I'd rather not have all go down at the same time. So...

I have a generic Linksys router (with the atrocious new Smart Wifi). Man I need to change the firmware to the good stuff, but that's another day. So one public IP, 3 VM's all with unique internal IP's i.e. 192..1/2/3. The router does not allow port forwarding to multiple IP's using the same port (80).

If way to much to do, I'll bite the bullet and move them into the same VM and vhost the different sites, but my thoughts were to use ANOTHER VM. A virtual router. I can think of some router/firewall VM's like pfSense, m0n0wall, but I'm just looking for something simple and easy to get going, but I'm assuming it will need to act slightly like a vhost would by taking in the port 80 request from the router, then dispersing the traffic to the 3 VM's holding the web servers by using the host headers (I think).

Anyone have a suggestion, better method etc.? Much appreciated in advance, and as much as putting them all under one VM roof would solve this instantly, in my case, the separation of VM's kinda trumps it.

But very open to thoughts. Cheers.

share|improve this question

migrated from serverfault.com Dec 11 '13 at 15:41

This question came from our site for professional system and network administrators.

1  
If you care about uptime that much, why not rent a vps and host the servers there? –  tombull89 Dec 11 '13 at 8:48
    
Should have been specific in terms of just talking about virtual routing. –  Hunter Dec 11 '13 at 8:50
1  
Question is, is each server hosting it's own site, or does each server hold a copy of all three sites? You want a load balancer sort of thing but using one at home? I wouldn't know where to start. –  tombull89 Dec 11 '13 at 8:54
    
Each one has it's own site. Although I just have the feeling that a virtual router 'may' do the trick. Like your answer, just not sure where to begin. Starting to feel like separating them is just too much hassle. –  Hunter Dec 11 '13 at 8:55
5  
Set up an apache server with mod_proxy and proxy each of the sites to its own server. THe router need only do port forward to that one apache server. –  Jenny D Dec 11 '13 at 9:42

3 Answers 3

Set up one more vm as proxy, that would direct traffic to appropriate vm using domain name.

share|improve this answer
    
you can setup nginx as a proxy on one of the VMs you have and use it as WebProxy. Here is docs for Nginx HTTP proxy module: nginx.org/en/docs/http/ngx_http_proxy_module.html Another HOWTO: cyberciti.biz/tips/using-nginx-as-reverse-proxy.html –  user2991674 Dec 11 '13 at 13:05
    
While that's probably the best way to do this. That is not an answer unless you give some pointers on how to apply this idea and links to documentation/howtos. –  Kwaio Dec 11 '13 at 15:48

I have tried various solutions and the success I have is using Apache2. It comes with virtual hosting feature.

You will need to do a little "wiring" the Apache2 but, I am including my conf as a guide for you. How this works: apache2 operates on "Name-Based Domain" feature where it runs as many sites as I want but on one public IP. [I am a developer which explains why these many sites].

   $ sudo apt-get install -y apache2 apache2-dev apache2-threaded-dev

Wiring your apache2.conf by adding these three lines in the end of the conf

   include httpd.conf
   <VirtualHost *>
   </VirtualHost>

Configure your httpd.conf with this guide; adjust accordingly to your case. By the default as new installation, you will not see httpd.conf but Apache2 will respond if it finds httpd.conf sitting in /etc/apache2 directory.

    $ sudo touch /etc/apache2/httpd.conf

and add this to httpd.conf. Big emphasis is to leave :80 untouched. When you see '## EDIT THIS*'; that's where you can edit to your own liking meanwhile leaving others untouched.

   <Directory "/var/www">  ***## EDIT THIS***
      Options Indexes FollowSymLinks
      AllowOverride All
   </Directory>

    <location /cgi-bin>
    AddHandler cgi-script .cgi .pl
    Options -Indexes +FollowSymlinks +ExecCGI
    </location>


  <VirtualHost *:80>
    ServerName example.ca  ***## EDIT THIS***
    ServerAlias www.example.ca ***## EDIT THIS***
    DocumentRoot /var/www/example_ca/html ***## EDIT THIS***
    <Location "/">
            Order Deny,Allow
            Deny from all
            Allow from all
    </Location>
      CustomLog /path/to/your/preferred/log-folder/access.log common ***## EDIT THIS***
      ErrorLog /path/to/your/preferred/log-folder/error.log ***## EDIT THIS***
   </VirtualHost>

  <VirtualHost *:80>
    ServerName sample.ca ***## EDIT THIS***
    ServerAlias www.sample.ca ***## EDIT THIS***
    DocumentRoot /var/www/sample_ca/html ***## EDIT THIS***
    <Location "/">
            Order Deny,Allow
            Deny from all
            Allow from all
    </Location>
      CustomLog /path/to/your/preferred/log-folder/access.log common ***## EDIT THIS***
      ErrorLog /path/to/your/preferred/log-folder/error.log ***## EDIT THIS***
   </VirtualHost>

then...

   $ sudo service apache2 restart

and voila! Good luck!

EDIT: Keep in mind - after setting up sites and tested to be operational on your local network, you need to update DNS with your DNS service provider (where you registered these domains) and update your ip address (where you are hosting your machine with these multi-sites).

share|improve this answer
    
Just to confirm, with this approach, he'll be hosting all sites on a single vm, correct? Not a big deal to and is actually probably better in terms of resource allocation. –  BigHomie Dec 11 '13 at 13:33
    
Confirmed, MDMoore313. Reason: Apache2 already have the virtual hosting technology and can operate multi-sites off the single machine. –  Faron Dec 11 '13 at 15:33

The router does not allow port forwarding to multiple IP's using the same port (80).

This isn't possible with standard TCP/IP, by the way. You need a program, i.e. a proxy, accepting requests on the port, looking at the requests, then shunting requests around accordingly.


Apache and other web servers have a "reverse proxy" feature that can be used to "split" your incoming traffic. A reverse proxy tells Apache that requests for a certain web path, i.e. "yourdomain/directory1" should be thrown to another webserver, and the responses from that webserver thrown back to the original client.

Beware, however, that if you have applications running on this webserver (PHP, etc.) that they may need to have settings changed as their externally facing URL will be different. You may have to tell a PHP application that it lives at "yourdomain/directory1" instead of "yourdomain" so it can generate links correctly. It's possible to tell Apache to rewrite traffic from the backend server before it gives it back to the client but this is difficult and you want to avoid it if possible. Applications that generate links with Javascript can be especially problematic, so not all web applications are easily "reverse proxyable."

So install Apache on a fourth "front end" VM - forward your incoming TCP 80 to this VM. You also need to make sure this VM can reach your other VMs on your "virtual network." Then, on your "front end" VM, you can set up a separate reverse proxy for each website.

Here is the relevant Apache configuration details, using the ProxyPass and ProxyPassReverse directives.

You can also get elaborate and implement caching, which would help performance.

share|improve this answer

Your Answer

 
discard

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