0

I am attempting to host multiple sites on a single server by using virtual hosts however I am having a bit of an issue.

A bit of info before I begin,

-I am using Ubuntu Server 12.04
-I am using Apache2
-I have two domains and two sites, stored in /var/www/site1 and /var/www/site2

I have put this in my httpd.conf file and from what I understand it should have worked, allowing domain1 to go to site1 and domain2 to go to site2 but instead domain1 and domain2 go to site1 only.

NameVirtualHost *80

<VirtualHost *:80>

    DocumentRoot "/var/www/site1"
    ServerName domain1.com
    ServerAlias www.domain1.com

</VirtualHost>

<VirtualHost *:80>

    DocumentRoot "/var/www/site2"
    ServerName domain2.com
    ServerAlias www.domain2.com

</VirtualHost>

As I say, it just loads up site1 regardless of which domain I put in. If I swap them around so domain2 is the first virtual host then it shall load up that one only.

What am I doing wrong?
Thank you in advance!

3
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by Octet
0

The only thing I see out of place is the quote marks arount the Document Root Normally I use the path /var/www/html/domainname.com. Below is the first entry from one of the servers I manage.

<VirtualHost *:80>
       ServerAdmin webmaster@chartwriter.com
       DocumentRoot /var/www/html/chartwriter.com
       ServerName chartwriter.com
       ErrorLog logs/chartwriter.com-error_log
       CustomLog logs/chartwriter.com-access_log common
</VirtualHost>
0

Thanks, I have tried it with and without quotes, have tried using the default one and editing ... I've tried everything but I just cannot get it to work...

What I think I am going to have to do is manually get the URL and redirect it with a PHP script.

0

how many files does ls /etc/apache2/sites-enabled output? I am wondering if you have more than one site-enabled with some conflicting configurations.

0

Can you post the contents of ~/hosts.txt after running sudo cat /etc/apache2/sites-enabled/site1 > ~/hosts.txt && cat /etc/apache2/sites-enabled/site2 >> ~/hosts.txt

replacing site1 and site2 with the actual names of your sites-enabled files.

hosts.txt will be in your home directory.

0

Thank you for your time androtheos however I have come up with another solution to solve the problem.
123-Reg which I purchased the domain from change the headers so I don't think it would work anyway, instead I have created a PHP script which takes the HTTP referrer and redirects depending on that.

Thanks for the help though.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.