[Apache] Host 2 Websites?

Soldato
Joined
6 Jan 2005
Posts
3,633
Location
Cambridge
Hi, I've had a look around the internet and I'm still not entirely sure how do this.

I've got an apache server, I can make it so when I direct a domain to the IP it will open the website which it's hosting, but now I want to host 2 websites on the server, how can I do this?

So I want, for example,
domain1.com to go to /var/www/domain1.com/index.php
and domain2.com to go to /var/www/domain2.com/index.php

How can I make it so Apache realises which domain is being used and sends the data according to that?
The server is running CentOS if that changes anything.

Any help will be greatly appreciated.

Thanks,
yhack
 
You need to use virtual hosts for this. Here's a sample from the httpd.conf on my Windows development machine:

Code:
<VirtualHost *:80>
    DocumentRoot "/Documents/Development/Web/Docroot"
    ServerName localhost:80
	
	<Directory "/Documents/Development/Web/Docroot">
		Options Indexes FollowSymLinks Includes ExecCGI
		AllowOverride All
		Order Allow,Deny
		Allow From All
	</Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Documents/Development/Web/Projects/Theory/www"
    ServerName theory.localhost
	
	<Directory "/Documents/Development/Web/Projects/Theory/www">
		Options Indexes FollowSymLinks Includes ExecCGI
		AllowOverride All
		Order Allow,Deny
		Allow From All
	</Directory>
</VirtualHost>
 
Last edited:
Excellent, that worked perfectly, thanks!

Is there any way to make www.domain1.com and domain1.com go to the same place without putting that code twice with both domains?
 
Use ServerAlias under the ServerName:

Code:
<VirtualHost *:80>
ServerName www.domain1.com
ServerAlias domain1.com

Thats the top few lines of my virtualhost :)
 
Back
Top Bottom