On my CentOS virtual machine I set up an Apache server. I followed this link: How to set up Apache server.

Then everything worked fine as expected; however, when I removed the example.com entry from the /etc/hosts file, I expected it to reach for /var/www/html instead of example.com still however it still reached only for example.com index html when I reach for my local IP address. I just want to understand when should it prefer to reach out for folders like example.com and leave out /var/www/html/.

It confused me a bit. I want to know when is this one used and when is the other used as in /var/www/example.com and /var/www/html respectively.

closed as off-topic by Jeff Schaller, Rui F Ribeiro, Anthon, Stephen Rauch, GAD3R Aug 13 '17 at 15:02

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, Rui F Ribeiro, Anthon, Stephen Rauch, GAD3R
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Did you do "service httpd reload"? – cutrightjm Aug 5 '17 at 21:01
  • i did restart the computer after every edit , i did try that order now after trying still shows example.com, when i remove example.com from sites-enabled example2.com takes place , when i remove both example.com and example2.com the index.html in /var/www/html is finally the one loaded – Mohamed Ashref Aug 5 '17 at 21:08

Well i got what happened in case anyone faces the same issue, In the /etc/httpd/conf/httpd.conf i included the virtual hosts file in /etc/httpd/conf.d which specified the listen id for

<VirtualHost *:80>

Which means by this documentation VirtualHosts Common Questions that it will listen on all the ips, not letting the main server in /var/www/html serve any requests.

And because "example.com" is declared before "example2.com" (assuming that '.' comes before '2' in folder organization) it has the highest priority to serve the requests.

For example if we were to change "example2.com" to "aexample2.com" it will have a higher priority because it will be declared first due to begin read first from the folder /etc/httpd/sites-enabled because 'a' comes before 'e' in alphabetical order (As my tests showed).

Not the answer you're looking for? Browse other questions tagged or ask your own question.