Specifying the default virtualhost in Apache 2.4 when using the vhost.d directory with one file per vhost?

StackOverflow https://stackoverflow.com/questions/22276984

  •  11-06-2023
  •  | 
  •  

Question

I'm configuring a new Apache 2.4 webserver. I've installed and run Apache many times in the past but always tended to stick to what I learned in the early days when it came to configuration files, in particular I'd usually just have one virtualhosts.conf file somewhere and add all virtual hosts to it, with the first one in the file automatically becoming the default host that was served if someone visited the server just by IP address. Where a server had multiple IPs, then the default host would be the first one in the file configured to answer on that IP.

However with the new box I'm trying to do things "properly", which I gather means that in /etc/apache2/vhosts.d I should create a separate config file for each virtualhosted website. Which works, and is fine so far - but there doesn't seem to be any specific mechanism to specify which one should be the default for each IP on the server, other than them being arranged alphabetically. Ok, I can work round this by naming the one I want to be first 00-name.conf, so it automatically comes first in ASCII, but that seems a bit clunky - is there a formal method for instructing Apache that a specific virtualhost out of the many that may exist for a given IP is to be the default one?

I've tried Googling, and reading the Apache documentation, but not found anything that answers this specific question.

Was it helpful?

Solution

There's nothing in the Apache documentation because that default configuration is a debian/ubuntu invention. In that environment, using numbered config files to determine the default VH for a set of name-based virtual hosts is absolutely a standard thing to do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top