Fedora Linux Support Community & Resources Center
  #1  
Old 20th April 2004, 07:23 AM
Ronno Offline
Registered User
 
Join Date: Apr 2004
Location: Victoria, BC
Posts: 20
Virtual Hosts in Apache

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:

http://subdomain.ipaddress or
http://ipaddress:port

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?

Thanks,

Last edited by Ronno; 21st April 2004 at 06:07 AM.
Reply With Quote
  #2  
Old 20th April 2004, 07:07 PM
ieatlint Offline
Registered User
 
Join Date: Mar 2004
Location: Northern California
Posts: 31
It cannot be done.
Why?

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 69.56.242.106. So it gives you that. If you go to http://69.56.242.106 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...
Reply With Quote
  #3  
Old 20th April 2004, 07:11 PM
kel Offline
Registered User
 
Join Date: Apr 2004
Posts: 27
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.
Reply With Quote
  #4  
Old 20th April 2004, 08:39 PM
Ronno Offline
Registered User
 
Join Date: Apr 2004
Location: Victoria, BC
Posts: 20
Kel, that sounds like a great solution. Do you have any advice or know of any instructions on setting that up?
Reply With Quote
  #5  
Old 21st April 2004, 05:07 AM
kel Offline
Registered User
 
Join Date: Apr 2004
Posts: 27
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....

Last edited by kel; 21st April 2004 at 05:09 AM.
Reply With Quote
  #6  
Old 21st April 2004, 05:20 AM
Ronno Offline
Registered User
 
Join Date: Apr 2004
Location: Victoria, BC
Posts: 20
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.
Reply With Quote
  #7  
Old 23rd April 2004, 02:44 PM
awesomejt Offline
Registered User
 
Join Date: Apr 2004
Location: Charlotte, NC, USA
Age: 37
Posts: 28
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.
Reply With Quote
  #8  
Old 24th April 2004, 05:18 PM
kosmosik's Avatar
kosmosik Offline
Registered User
 
Join Date: Apr 2004
Location: Warsaw, Poland
Age: 32
Posts: 1,085
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.
Code:
domain.tld -> your_ip
foo.domain.tld -> same_ip
bar.foo.domain.tld -> same_ip
... etc.
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.
Reply With Quote
  #9  
Old 25th April 2004, 07:36 PM
Ronno Offline
Registered User
 
Join Date: Apr 2004
Location: Victoria, BC
Posts: 20
Work Around

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/.

Cheers,
Reply With Quote
  #10  
Old 30th December 2004, 01:54 PM
DRE.ORGY.NET's Avatar
DRE.ORGY.NET Offline
Registered User
 
Join Date: Nov 2004
Location: Sydney, Australia
Posts: 210
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

domain1 111.222.333.444
domain2 111.222.333.444

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.
Reply With Quote
Reply

Tags
apache, hosts, virtual

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache Virtual Hosts stewartm82 Servers & Networking 2 28th March 2006 01:22 PM
Apache 2, Virtual hosts, DNS nickdangr Servers & Networking 3 23rd January 2006 07:02 PM
Apache 2, SSL and Virtual hosts nicha Servers & Networking 1 13th March 2005 06:57 AM


Current GMT-time: 19:31 (Friday, 24-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat