Apache/2.4.6 (CentOS)
For a while now, I've had a catchall page setup for my Apache server so bots would not crawl my main site unless they had my domain name.
Recently however, I noticed this no longer works with my config. When loading the page by IP address (let's say 10.20.20.10), I get the main site (let's say mysite.net) instead of the catchall.
The config looks like this:
<VirtualHost _default_:80>
ServerName default
# More config ...
</VirtualHost>
<VirtualHost _default_:443>
ServerName default
# More config ...
</VirtualHost>
<VirtualHost 10.20.20.10:80>
ServerName mysite.net
# More config ...
</VirtualHost>
<VirtualHost 10.20.20.10:443>
ServerName mysite.net
# More config ...
</VirtualHost>
Running apachectl -S revealed to me that it is not being loaded as the default:
10.20.20.10:443 is a NameVirtualHost
default server mysite.net (/etc/httpd/sites-enabled/01-mysite.conf:24)
port 443 namevhost mysite.net (/etc/httpd/sites-enabled/01-mysite.conf:24)
*:80 localhost (/etc/httpd/sites-enabled/00-catchall.conf:2)
*:443 localhost (/etc/httpd/sites-enabled/00-catchall.conf:16)
I was able to find a way to have my catchall load by default, but it required that I changed my catchall to the same listen IP as my main virtual host. Not the most ideal solution. I'd imagine changing all vhosts to * would also do it, but that's not ideal either.
Based on observation, it appeared like httpd prefers a closer match and takes an IP match over "*". Can anyone shed light on why Apache does not load the first vhost and what might fix this?
*before then switched to_default_since it was more symbolic. In both cases though the same result happened. As you said, I feel Apache is treating mysite.net as the first vhost for 10.20.20.10. – Datus Aug 19 '16 at 01:17/etc/apache2/sites-enabled. There's a file called000-default.confthat contains the catchall default site. It gets loaded when I connect via IP (verified). Each vhost is defined with<VirtualHost *:80>. I'm assuming000-default.confloads first due to it's filename and that's the only reason it's default. It'sApache 2.4.18. Does any of this help you? – Ryan Babchishin Aug 19 '16 at 01:2500-catchall.confbeing my desired default and01-insertsite.confbeing my main site. For the sake of trying things I included the file explicitly in the mainhttpd.confwith the same effect.I'm running this on a CentOS 7 host. The structure looks like Ubuntu on my server because I liked how they organized it. ;-)
– Datus Aug 19 '16 at 01:37apachectl -S. – Ryan Babchishin Aug 19 '16 at 01:45