View Full Version : Virtual Hosts in Apache
20th April 2004, 07:23 AM
I want to set up virtual hosts on my fedora workstation so I can develop and share beta versions of Web sites with my clients.
My fedora box is part of a Windows workgroup and receives its IP address from a router via DHCP. Is it possible to set up virtual hosts so that a client can access his/her site at:
All my googling has given me instructions that don't seem to apply to this situation. How do I set this up? Can anyone suggest some resources to learn more about configuring this?
20th April 2004, 07:07 PM
It cannot be done.
Because the virtualhosting works on a rather odd principle. The server gives the website to the browser based on what the browser thinks it's accessing.
Using this very website as an example, which is running virtual hosting. Your browser tells the daemon it wants "fedoraforum.org" at 126.96.36.199. So it gives you that. If you go to http://188.8.131.52 you don't get fedoraforum.org.
You need a dns setup of some sort..
You can setup your own dns server, OR you could modify the hosts file on each computer.
Forgot exactly where it is on win2k/xp...
winnt\system32\ ... something
File simply is called "hosts" and it works just like /etc/hosts on *nix does. If you configure on all computers who want to access the sites, and the server itself to do like:
10.0.0.1 bobsaget.com chinesepeople.com
Then you can configure virtualhosting...
20th April 2004, 07:11 PM
The real power of using virtual hosts is that you can have the server on a single IP address respond to many names. Given that IP addresses and names are not easily mixed as you describe and will likely end up being more complicated than you intend. Does this arrise because you don't have DNS (domain name resolution) within your workgroup? A more workable solution, if you don't have name resolution, is http://ipaddress/client... it is a simple matter to then reconfigure the site to become the 'root' of your virtual host (http://client) in the future.
20th April 2004, 08:39 PM
Kel, that sounds like a great solution. Do you have any advice or know of any instructions on setting that up?
21st April 2004, 05:07 AM
Actually, this is easy to do. Just set up a directory for each client beneath the 'DocumentRoot' defined in /etc/httpd/conf/httpd.conf, by default this is /var/www/html. This is the simple approach, but sometimes simple is better...at least at first.
So, for example, if your client is boba, the directoy /var/www/html/boba would be the root of his website and would be accessible via your IP address, http://192.168.0.1/boba.
Now there are issues about the location of site-wide directories that you might be used, for example cgi-bin, etc., but this can be addressed later as you become more proficient with your website management....
21st April 2004, 05:20 AM
Ahhh, I see what you are getting at now. The problem is I am already doing this but run into the problem that the DocumentRoot is not accurate for each site. Let me exlpain.
I build sites in PHP and often create separate header files that are included into each page. These headers import external style sheets and link to other pages relative to the DocumentRoot. Problem is the DocumentRoot is one level too high. Therefore the link "href="/" would not keep me within the folder dedicated to that site.
I thought setting up VirtualHosts would be the solution.
23rd April 2004, 02:44 PM
I run into the same problem if I just create directories under apache. I use the virtual host method.
You can assign your computer either a unique IP for each client you use -- or easier to manage, use named virtual hosts.
Actually, I think if you use dynamic DNS you should be able to do what you want. HOWEVER, configuration is NOT easy. If you only have a handful of clients, then just edit the hosts file on your windows box.
The hosts file should be located at (on Windows 2000):
c:\Winnt\System32\drivers\etc (I believe that is correct)
I suspect it lives at the same location on XP -- but I have not looked for it yet.
If you don't mind getting your hands dirty, you could setup your Fedora box to serve DNS as well. I believe Webmin has a module that helps make DNS easy, but I haven't worked with it (nano is my DNS editor).
On Fedora, adding a virtual host isn't difficult. You can create a separate conf file for each virtual host/client you want and put them in the /etc/httpd/conf.d/ directory (that's what I do).
The easiest solution is to give your Fedora box a static IP and then point all your client "domain names" to that IP and setup Named virtual hosts. If you have a lot of clients, go the DNS route.
24th April 2004, 05:18 PM
You have two choices - running own DNS server and setting up proper domains - this is harder. Or get a domain name with wildcards so any call to your domain leads to your IP. F.e.
domain.tld -> your_ip
foo.domain.tld -> same_ip
bar.foo.domain.tld -> same_ip
and then setup Apache for using name based Virtual Host (Apache documentation has good HOWTO on this topic). Second solution is easier and since you need it only for developement purposes it would be IMHO good setup.
25th April 2004, 07:36 PM
Thanks for all the great suggestions. In the end I went with a very straightforward solution. I simply created a "$documentRoot" variable in PHP and use it whenever I need an absolute path to an image or link. This is a bit cumbersome but now I have the added benefit of being able to open my firewall and have clients view beta version of their site at http://ipaddress/clientname/.
30th December 2004, 01:54 PM
This wasnt that hard to get around. If you created a virtual host using the same IP address and the same port it there is a way to make it accessable from outside. How?
Well say for instance you want people to access two websites http://domain1 and http://domain2 if these are two virtual hosts (dont forget to put these both in your local /etc/hosts) now how apache works (this is also true for IIS its called host headers) is that if you use name virtual host on the same server and the same port it will figure out which site to go to depending on how its called by the client browser.
So on your server you if you open up a browser and do a http://domain1 and then a http://domain2 it will go to its respective site.
The hardest part is DNS , because domain1 and domain2 arent actual DNS entries on any server other than your internal one no one other than you will be able to see them. So how can you get around this? Well if you get your customers to add your ip address to their hosts file (c:\windows\system32\drivers\etc\hosts on windws xp) with two different name entries eg
this should work because when they type http://domain1 in their browser it will check the hosts file for an entry and because the browser is hitting your website using domain1 it will hit the correct website.
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.