Wildcard include your site configuration files:
Include path/to/site/confs/*httpd.conf
Organize your site conf files so they are loaded in an expected order. Example...
01-httpd.conf
02-site1-httpd.conf
03-site2-httpd.conf
etc...
Apache will read these in order. Then create one that will always load last to catch any unmatched virtual hosts and return a 404 instead of loading a default site.
99-catchall-httpd.conf
<VirtualHost *:8080>
ServerName null
ServerAlias *
Redirect 404 /
</VirtualHost>
<VirtualHost *:8443>
ServerName null
ServerAlias *
Redirect 404 /
</VirtualHost>
Be sure to replace the ports with whatever ports your httpd listens on. Or if you have httpd listening on specific interfaces, you'll need to add a catchall for each interface instead, like so:
<VirtualHost 192.168.1.101:8080>
ServerName null
ServerAlias *
Redirect 404 /
</VirtualHost>
<VirtualHost 192.168.1.101:8443>
ServerName null
ServerAlias *
Redirect 404 /
</VirtualHost>
<VirtualHost 192.168.1.102:8080>
ServerName null
ServerAlias *
Redirect 404 /
</VirtualHost>
<VirtualHost 192.168.1.102:8443>
ServerName null
ServerAlias *
Redirect 404 /
</VirtualHost>
Hope this helps. I use this method to load sites in the order I specify and prevent unmatched virtual hosts from loading an unexpected site unintentionally.
Neither my first or last v-host file is used. I think apache has changed. – Cobolt – 2019-06-18T15:55:18.823
Thanks but could you please elaborate? I can't get this to work. – Ryall – 2011-09-07T12:34:12.870
2How are your apache2 configuration files layed out? Or which operating system do you use? Apache reads the configuration in a certain order, and the first VirtualHost it sees is the default one. It receives all traffic from unknown host names. So if you have a single configuration file, the first VirtualHost is it. If you have multiple ones, like on most linuxes, it may be the one called 0default or so... – Moritz Both – 2011-09-07T15:00:16.270
I put some default configurations in the
ports.conf
. It wasn't working because I tried to match *:80 when I was using <ip>:80 on my virtualhosts. Instead I had to create a separate default entry for each IP and it works now. – Ryall – 2011-09-08T15:31:28.587