Mobile app version of vmapp.org
Login or Join
Shanna517

: Vhost set up help -- domain and ip point to the same site I have these virtual hosts set up however when I browse to domain.com or 123.45.67.89 they both point to /var/www/html/. How can

@Shanna517

Posted in: #Virtualhost

I have these virtual hosts set up however when I browse to domain.com or 123.45.67.89 they both point to /var/www/html/. How can I get them set up so they point to correct DocumentRoot?

<VirtualHost *:80>
ServerName 123.45.67.89
DocumentRoot /var/www/html/
</VirtualHost>

<VirtualHost *:80>
ServerName domain.com
DocumentRoot /var/www/vhosts/domain.com/htdocs
</VirtualHost>


EDIT: I actually had a seperate vhosts.conf file located in /etc/httpd/conf.d/. Subsequently this was being loaded (unbeknownst to me) by Include conf.d/*.conf before --

NameVirtualHost *:80
Listen 80


I have moved the vhosts out of that directory and into /etc/httpd/conf/vhosts/ and amended my Include file at the bottom of httpd.conf to --

Include /etc/httpd/conf/vhosts/*.conf


I have also tried uncommenting ServerName and defining it as my servers IP and removing the first VirtualHost.

The result of this is that domain.com points to the correct site though the IP points to that site now too.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Shanna517

1 Comments

Sorted by latest first Latest Oldest Best

 

@Phylliss660

Make sure these are in your Apache configuration BEFORE the VirtualHost containers:

NameVirtualHost *:80
Listen 80


The reason you see the same content on both URLs is because Apache uses the FIRST VirtualHost as the "default" so any hostname not matching a VirtualHost will automatically be served as the first one you have.

Please report back the results.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme