We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,194 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Apache2 Virtual Hosts - Only Loading One Webpage

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
2 Days
Discussion Span
11 Months Ago
Last Updated
7
Views
Question
Answered
AHarrisGsy
Posting Pro in Training
485 posts since Nov 2011
Reputation Points: 52
Solved Threads: 40
Skill Endorsements: 13

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>
rch1231
Veteran Poster
1,040 posts since Sep 2009
Reputation Points: 142
Solved Threads: 154
Skill Endorsements: 12

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.

AHarrisGsy
Posting Pro in Training
485 posts since Nov 2011
Reputation Points: 52
Solved Threads: 40
Skill Endorsements: 13

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.

androtheos
Light Poster
46 posts since May 2012
Reputation Points: 6
Solved Threads: 5
Skill Endorsements: 1

It has two, one for each of the two sites I have?

AHarrisGsy
Posting Pro in Training
485 posts since Nov 2011
Reputation Points: 52
Solved Threads: 40
Skill Endorsements: 13

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.

androtheos
Light Poster
46 posts since May 2012
Reputation Points: 6
Solved Threads: 5
Skill Endorsements: 1
Question Answered as of 11 Months Ago by androtheos and rch1231

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.

AHarrisGsy
Posting Pro in Training
485 posts since Nov 2011
Reputation Points: 52
Solved Threads: 40
Skill Endorsements: 13

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0855 seconds using 2.83MB