1

I have setup 2 sites at my localhost. One at localhost:8197 and one at fc.localhost:8197 Of course, to make this work, I've edited my /etc/hosts file to include

fc.localhost 127.0.0.1 

So, these are my configurations for each site respectively:

000-default.conf (site located at localhost):

<VirtualHost *:8197> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/html/> Options +Indexes +FollowSymLinks +ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> 

fc.conf (site located at fc.localhost):

<VirtualHost *:8197> ServerAdmin webmaster@localhost DocumentRoot /home/alex/Documents/fc/Website/fc/html ServerName fc.localhost ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /home/alex/Documents/fc/Website/fc/html> Options +Indexes +FollowSymLinks +ExecCGI AllowOverride All Order allow,deny Allow from all Require all granted </Directory> </VirtualHost> 

Suppose that my local IP address is 10.8.210.51 and some pc in my local network puts 10.8.210.51:8197 in the address bar of their browser, then apache on my side will serve the first site (localhost) and not the second one (fc.localhost). The same things happens if I put 127.0.0.1:8197 in my address bar (server-side).

So, my question is, out of clear interest, how does Apache decides which site to serve and how can I change this behavior?

2 Answers 2

2

The short answer to your specific case: apache will serve the FIRST overlapping virtual host. Since 000-default is before fc.localhost in the alphabet the first virtualhost is loaded and served.

To answer what i assume is the follow up question: You can host many sites on the same IP:PORT using namedVirtualHosts

This technology relies on the Host Header in the HTTP spec.

And because of complications with SSL https virtualhosts are possible via Server Name Indication

1

This is called "name based virtual hosting", described here:

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.