I have this default 000-default.conf
:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And this one I created, my.conf
:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html
Redirect permanent / https://example.com/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/html
SSLEngine on
...
</VirtualHost>
</IfModule>
If I try example.com
on the browser, I get redirected to https://example.com/
, which is fine.
But if I try 123.45.67.89
I also get redirected to https://example.com/
.
Since both virtual servers (*:80) are a match for 123.45.67.89
, and no ServerName
is a match for 123.45.67.89
, I expected Apache 2.4 to select the one in 000-default.conf
. But it is not. Why?
My reference is this:
If multiple virtual hosts contain the best matching IP address and port, the server selects from these virtual hosts the best match based on the requested hostname. If no matching name-based virtual host is found, then the first listed virtual host that matched the IP address will be used