Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i setup virtual hosts??

Status
Not open for further replies.

JaybOt

Programmer
Apr 18, 2001
101
GB
Hi all,

I have apache running on a unix server and i have been looking at the virtual host section in the config file and was wondering what changes i would have to make to my config file and system to add a virtual doman. Is a dns entry required?

i know there is a virtual host directive that is set up as folllows ...

<VirtualHost XXX.XXX.XXX.XXX>
DocumentRoot /home/somebody/www
ServerName somename.com
ServerAlias ServerAdmin username@somename.com
ErrorLog /home/somebody/log/error_log
</VirtualHost>

but is this all i need? also, can i use ..

<VirtualHost hostname XXX.XXX.XXX.XXX:port>
<VirtualHost hostname:port>

again, any help appreciated

Jaybot &quot;Always know what you say, but don't always say what you know!&quot;
 
DNS! Make sure you have your DNS set up correctly.
Add something like this to your named.conf file:

zone &quot;name.com&quot; { type master; file &quot;db.name.com&quot;; };

THEN...make sure you have the db.name.com file in your /var/named directory. This file should look something like this:

<----------------->8------------>

@ IN SOA name.com. username.name.com. (
2001062801 ; serial number
10800 ; refresh after 3 hours
1800 ; retry after 30 minutes
604800 ; expire after 7 days
36000 ) ; minimum TTL of 10 hours
IN MX 10 prefix.yourserver.com.
IN NS prefix.yourserver.com.
IN NS dns.number2.com.

$ORIGIN name.com.
IN A XX.XX.XX.XX
coolo IN A XX.XX.XX.XX
mail IN CNAME prefix.yourserver.com.
www IN CNAME prefix.yourserver.com.

<----------------->8------------>

make sure that XX.XX.XX.XX is your IP and prefix.yourserver.com is your server name and keep the dots after all the .coms
dns.number2.com. would be a secondary dns entry...not required but good to have.
Make sure you change the serial number any time you change this file. Notice it's the date with a 01 after it.

Hope this gets you up!

s/ JohnnyDog

 
prefix = hostname.
coolo = hostname.

Hope this didn't confuse you. Sorry.

s/ JohnnyDog
 
You'll need some DNS entries and some httpd.conf entries. I use granite canyon to do my dns hosting since it's free and I live on a $0 budget. I have a global for all my virtual hosts, so anythingatall.mydomain.com points to my server and the virtual hosts point whatever.mydomain.com to the right location. It looks something like this.

; Name Servers
yourdomain.com. IN NS ns1.granitecanyon.com.
yourdomain.com. IN NS ns2.granitecanyon.com.
; A Records
localhost.yourdomain.com. IN A 127.0.0.1
node1.yourdomain.com. IN A xxx.xxx.xxx.xxx
; Aliases
IN CNAME node1.yourdomain.com.
*.yourdomain.com. IN CNAME node1.yourdomain.com. ; GLOBALOK
; MX records
yourdomain.com. IN MX 0 node1.yourdomain.com.

You can also do it how JohnnyDog said, but it will take more of your time to get things set up. I do it this way so I don't have to deal with my dns unless my internet providers change my IP. You may have to check with your dns host to make sure you can do wildcards in your domains.

The next thing you'll need is the directory directives. Every folder you use in your virtual hosts has to be set up in the directories and since you're using unix, you have to have those folders accessable by nobody. You can follow the already set up directory directive for the default page.

Next you'll need to identify each of the IP's/ports for the virtual hosts and then the virtual hosts themselves. Follow this example:

NameVirtualHost xxx.xxx.xxx.xxx:pp
NameVirtualHost xxx.xxx.xxx.xxx:80

<virtualhost xxx.xxx.xxx.xxx:pp>
ServerAdmin webmaster@yourdomain.com
DocumentRoot /home/somebody/www
ServerName virtualhosta.yourdomain.com
ErrorLog logs/virtualhosta-http-error_log
CustomLog logs/virtualhosta-http-access_log common
</virtualhost>

<virtualhost xxx.xxx.xxx.xxx:80>
ServerAdmin webmaster@yourdomain.com
DocumentRoot /home/somebodyelse/www
ServerName virtualhostb.yourdomain.com
ErrorLog logs/virtualhostb-http-error_log
CustomLog logs/virtualhostb-http-access_log common
</virtualhost>

asside from that, I don't think you need anything else except maybe some configuration of the ports on the system. You'll be able to go to and once you're done. I'm running about 25 virtual hosts on my server at present, some with htaccess authentication and others for SSL and so on.

I hope this helped. Enjoy!
Steve Kiehl
webmaster@nanovox.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top