Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Virtual host configuration for Apache Internet
From the editor: Would you like the ability to easily access web sites you set up by name, instead of by number? If so, you'll want to use Virtual Hosts in Apache which will let you do just that. Read the rest of the article for jaccorens' instructions on how to configure it. I have not done this yet on my machine, but intend to ... someday when I get some free time!

Here's how to add some named localhosts to your OS X setup:
  1. open the NetinfoManager and become admin under the domain menu > security > authenticate.

  2. duplicate the localhost entry under the machines entry

  3. rename this copy to your prefered sitename (www.yoursitename1.dev), I used ".dev" because it's not used on the internet!

  4. open your terminal.app and SU to root

  5. type 'open -e /private/etc/httpd/httpd.conf' (without the quotes)

  6. find "#NameVirtualHost" in httpd.conf file

  7. change this into: "NameVirtualHost *" (remove the # and add the *, don't type the quotes)

  8. at the end of the file, make an entry like this:
    <VirtualHost *>
    DocumentRoot /Library/WebServer/www.yoursitename1.dev
    ServerName www.yoursitename1.dev
    </VirtualHost>
  9. in your /Library/WebServer/ folder, make an folder named like above (www.yoursitename1.dev)

  10. want more virtual hosts? do step 2 & 3 (www.yoursitename2.dev, www.yoursitename3.dev enz..)

  11. repeat step 8 & 9

    works here, questions.. feel free :-)
    •    
  • Currently 2.63 / 5
  You rated: 4 / 5 (8 votes cast)
 
[37,737 views]  

Virtual host configuration for Apache | 11 comments | Create New Account
Click here to return to the 'Virtual host configuration for Apache' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
DNS Entry?
Authored by: Gwyrrdin on Apr 24, '01 04:00:15AM

Hi

Maybe a dumb question, but I always worked only with domainnames purchased by eq. an ISP.

What's the point of giving a local website a virtualdomain when it doesn't have a DNS entry?
Only yourself from behind your own OS X box will be able to find you?

Or am I completely wrong?

I hope so:)


regards

Gwyrrdin



[ Reply to This | # ]
It's easier!
Authored by: robg on Apr 24, '01 08:33:12AM

The names are only local (you should probably avoid using something that might be publicly usable, as you'd get odd results). However, it makes it much easier to remember what you're working on, if you have a number of sites.

Compare "127.0.01/customer1", "127.0.0.1/customer2" to "dev.customer1.mine" and "dev.customer2.mine". easier to rememember the name instead of the number/name.

-rob.



[ Reply to This | # ]
DNS Entry?
Authored by: Anonymous on Jul 30, '02 07:15:41AM

a) you can edit (ie break) your sites locally without affecting the 'live' site)

b) you can specify absolute path and they'll work

c) if you mimic your ISP's paths php includes etc will work



[ Reply to This | # ]
DNS Entry?
Authored by: timrob on Jul 31, '02 04:55:13PM

Well you can give different names to sections of your server.
If you setup an alias (CName?) in DNS that points to *.yourdomain.tld,
you can have http://foo.yourdomain.tld and http://bar.yourdomain.tld.
You can setup up as many of these Virtual Hosts as you like and refer
to them by name by using the "ServerName" directive in your
Virtual Host configuration.

ie.

NameVirtualHost *

<VirtualHost *>
DocumentRoot /path/to/site/html
ServerName foo.yourdomain.tld
</VirtualHost>

<VirtualHost *>
DocumentRoot /path/to/othersite/html
ServerName bar.yourdomain.tld
</VirtualHost>

You can also do this without touching NetInfo.



[ Reply to This | # ]
OK ... but
Authored by: moyashi on May 02, '01 10:40:47PM

OK, I was hoping that this setup would allow me to work on development sites without actually dialling up to the net ...

So how do :

call this from my browser; ie iCab ..... http://www.company1.dev or http://localhost/www.company1.dev?
My browser likes to hang since it can't find the correct location.

and, is this ok? /Library/Webserver/www.company1.dev

in Netinfo Manager I have:
ip_address 127.0.0.1
name www.company1.dev
serves ./local

Which brings me to another question I've been tying to figure out. I want to organize the WebServer directory so that I can work on my friends site and my own. This is all no-cash (free beer and dinner funding from my friend) work that I do for my friend but I also would like to have my own site cleanly setup, will the above HINT workf for me?

and while I'm here. I would like to imitate my hosted IP site setup:
/usrXYZ/public_html/XYZ/cgi-bin/
tye of format.

Any clues on this?

I'm sure a lot of dialup users could benefit from having a similar setup on their desktop as their IP.

Thanks



[ Reply to This | # ]
Answer for ya :)
Authored by: DracoNB on Jan 03, '02 08:59:28PM

Yes you can emulate how your ISP does their setup! :) I just did it with mine :)

just change this:

# Keep this first one to enable localhost/127.0.0.1 to still function

<VirtualHost 127.0.0.1>
DocumentRoot /Library/WebServer/Documents
ServerName localhost
</VirtualHost>

# Edit this to fit your needs :)
<VirtualHost 127.0.0.1>
DocumentRoot /path/you/want/to/use
ServerName www.yoursite.dev
</VirtualHost>

DracoNB



[ Reply to This | # ]
Answer for ya :)
Authored by: moyashi on Sep 02, '02 12:03:21PM

Whoo, missed this thread some how.

Thanks for the reply and sorry for the realllllly late thanks

:(



[ Reply to This | # ]
Global/local httpd.conf
Authored by: Anonymous on Jul 30, '02 08:33:27AM

Any reason not to put the <VirtualHost *> block in the user's own .conf file in /private/etc/httpd/users? Keeps your stuff separate from the 'main' stuff.

Also, don't forget to restart Apache from the Terminal when you're finished editing httpd.conf for your changes to take effect: sudo apachectl restart



[ Reply to This | # ]
Global/local httpd.conf
Authored by: bluehz on Jul 30, '02 08:54:39AM

I have all my virtual hosts in seperate files and it works great - I find it much easier to open the specific file for each domain rather than the main httpd.conf file. Use an include statement in the main httpd.conf to include as many seperate files as desired:

Include /path/to/vhost.conf



[ Reply to This | # ]
Without NetInfo?
Authored by: springstdigital on Jul 31, '02 11:47:00PM

It took me a while, but I finally got this kind of set up to work (and it works great!), but until I actually involved the NetInfo Mangager it didn't work. I had to create additional 'machine' entries as described in the original post of this thread. How could it be done without NetInfo? (just curious)



[ Reply to This | # ]
Virtual host configuration for Apache
Authored by: Anonymous on Mar 13, '03 03:07:49PM

Under Mac OS X 10.2 (a.k.a. Jaguar)

step 1 edit your `/etc/hosts` file like this:

##
# Host Database
#
# Note that this file is consulted when the system is running in single-user
# mode. At other times this information is handled by lookupd. By default,
# lookupd gets information from NetInfo, so this file will not be consulted
# unless you have changed lookupd's configuration.
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 www.yoursite1.test
127.0.0.1 www.yoursite2.test


step 2 edit your `/etc/httpd/httpd.conf` file like this:
at the end of the file;

#
# Use name-based virtual hosting.
#
NameVirtualHost *

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>
<VirtualHost *>
DocumentRoot /Library/WebServer/Documents/www.yoursite1.test
ServerName www.yoursite1.test
</VirtualHost>
<VirtualHost *>
DocumentRoot /Library/WebServer/Documents/www.yoursite2.test
ServerName www.yoursite2.test
</VirtualHost>

Now reboot your apache, and it should be all good!



[ Reply to This | # ]