Raees Iqbal
Raees Iqbal

Reputation: 2298

Apache 2 different Virtual Hosts point to first one

Well, I'm pretty new to this, so, I'm sorry if I'm making some stupid mistake but I've been trying to make my Apache Virtual Hosts work fine for different domains. I have one VPS with CentOS 6 and Apache 2 where I'm running 2 websites with diffent domain names; they were both working fine some days ago. But After I made some changes (i dont remember them) they're acting stupidly. The problem is that the both of the domains are pointing to the first document root in the vhosts file. This is my vhosts.conf

NameVirtualHost *:80

<VirtualHost *:80>
     ServerAdmin [email protected]
     DocumentRoot /var/www/domainme
     ServerName domain.me
     ErrorLog /var/www/log/domainme.log
</VirtualHost>
<VirtualHost *:80>
     ServerAdmin [email protected]
     DocumentRoot /var/www/domaincom
     ServerName domain.com
    ErrorLog /var/www/log/domaincom.log
</VirtualHost>

Everytime I try to access domain.com it gives me the index file of domain.me but if I put domain.com's configuration before the domain.me in vhosts file, and go to domain.me; it will give me the index of domain.com. I have two IP's for the VPS by the way. Thank for reading, hope that its not a big issue.

Upvotes: 3

Views: 1167

Answers (1)

Steel Brain
Steel Brain

Reputation: 4461

Try this one

Listen *:80
NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /path/to/domain1/
    ServerName domain1.com
    ServerAlias domain1.com www.domain1.com
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /path/to/domain2/
    ServerName domain2.com
    ServerAlias domain2.com www.domain2.com
</VirtualHost>

Upvotes: 2

Related Questions