Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 380
Raees Iqbal Avatar asked Dec 10 '25 05:12

Raees Iqbal


1 Answers

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>
like image 68
Steel Brain Avatar answered Dec 13 '25 12:12

Steel Brain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!