2

As i am working with Apache2.2 more and more lately this thought crossed my mind (apologies if this seems a 'silly' question, still learning alot)

Are there any blatant disadvantages if you use just one file in hosts-available to configure multiple vhosts listening on the same port?
Besides not being very practical to get an overview of what sites are active, of course.

What are the trade-offs if you were to declare, let's say, 100 sites in one file?
Reaction speed comes to mind, parsing that file will take longer of course, but when does this become a real issue towards loading times etc?
Also the port would get hammered by requests if it are busy sites, but again, when does this become a problem?

Note that i realise this is more of a 'debate' question but a i have not found any useful info on this specific situation so i figured i'd come ask here.


In response to the comment and answer (can't add comments myself yet)

Yes it seems i have mixed up the terminology, i do mean defining many vhosts in one config file, not one vhost with many different site entries. This would indeed be very tricky (near impossible?) in many situations. I have edited the title to clarify the question.

Jake
  • 248
  • 2
  • 7
  • Using one file for the config or using one vhost are two separate issues! If you only use one vhost (virtual host) then you will have to do all sorts of trickery depending on the Host: header passed to serve out different content. Methinks you mean one config file for many virtual hosts, not one vhost. – wurtel Sep 18 '14 at 07:05

2 Answers2

4

I think you're asking two different questions:

  • Whether it's okay to put a lot of configuration in one file, instead of splitting it over multiple files. For performance, I don't think this matters at all (though management is another question, as @dwalker109 answered). The difference in load time to parse 100 small files versus 1 large file is insignificant, and would only happen when the server was reloaded anyway. The configuration is loaded once, and then is held in memory after that.

  • Whether it's okay to serve lots of virtual hosts on the same IP address and port. Yes, this is perfectly fine. If the number of vhosts was very large - much more than 100 - then Apache would need a lot of memory to hold all of the configuration. But again this is insignificant for 100 sites. If the sites are busy, then yes, performance could suffer, but I don't think it matters much if the traffic is on one vhost or spread over many.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
2

You touched on this in your question but I will expand on it here.

  • The management overhead in keeping lots of vhosts defined in a single file can become quite problematic in my experience. You won't see any real performance hit, but finding and working on a vhost in that arrangement can be frustrating. If you ever pass this install on to somebody else, they probably won't thank you for it.

  • By doing this you are going against the standard Debian way of managing sites, and the a2ensite type tools will no longer work as intended. In the name of convention of configuration, I would urge anybody to try to stick to the vanilla way of doing these things.

dwalker109
  • 41
  • 2
  • Management would indeed become a nightmare, i myself would never implement sometthing like this. There are times i put multiple vhosts in one file, for example if they share the same codebase and need to be approached from different names.But i am not about to chuck all vhosts in one big file. It is more a 'suppose if i would' kind of thing that crossed my mind. – Jake Sep 18 '14 at 15:06