1

I'm using Apache 2.2 and let it serve domains foo.example.com and bar.example.com with <VirtualHost> statements:

<VirtualHost 127.0.0.1:80>
  ServerName foo.example.com
</VirtualHost>
<VirtualHost 127.0.0.1:80>
  ServerName bar.example.com
</VirtualHost>

My problem is, that I need to add configuration options, that are only targeted at foo.example.com, in a separate file (let's say, /etc/apache/sites-enabled/foo.conf). This file will be included, before the VirtualHost statement is issued, but it can't be embedded inside it.

Can I (and if yes, how) target configuration settings to foo.example.com requests only, outside the VirtualHost container?

Boldewyn
  • 239
  • 4
  • 13
  • Why on heart do you want the Include statement before the VirtualHost statement? – SamK Jan 14 '11 at 14:44
  • I too must ask why it is that you'd wish to do this ? Your configuration directives seem to be host specific, so why can you not input them within the Vhost ? If you could expand on this, I'm sure we could come up with something. – jonathanserafini Jan 14 '11 at 14:47
  • Unfortunately, if it'd be only a wish, it could be simply revised. I have a piece of management software, that puts the Vhost statements at the end of httpd.conf, while allowing user-defined directives just above them. – Boldewyn Jan 14 '11 at 15:31

3 Answers3

2

No, you can't. This is exactly what VirtualHost blocks are for. If you can give us a more thorough description of exactly what problem you're trying to solve, we may be able to suggest some alternatives.

larsks
  • 43,623
  • 14
  • 121
  • 180
  • Actually, I'm forced to use a management software, that puts user-defined config options in front of VHost statements in the main httpd.conf. I *could* circumvent this by manually editing httpd.conf, but then I'd lose all advantages of the web frontend that comes with the tool. – Boldewyn Jan 14 '11 at 15:32
1

Depending on exactly what you want to achieve .htaccess files might be what you need.

dunxd
  • 9,632
  • 22
  • 81
  • 118
  • At the moment I'm trying to move as much as possible from .htaccess files to the config. Also, I'd like to specify custom log files and stuff. So, thanks for the answer, but in my case it doesn't apply unfortunately. – Boldewyn Jan 15 '11 at 09:00
1

So VirtualHosts directives and .htaccess files are out of the question. So the only thing left is to run a different instance of Apache for each subdomain, which would have a completely separate configuration file, which might potentially work with your management software.

If none of those work for you, then you have drifted so far from the standard way of doing things that you probably need to write your own fork of Apache to deal with your specific requirements ;-)

dunxd
  • 9,632
  • 22
  • 81
  • 118
  • Hm. I think I'd rather drop the management web frontend than forking Apache. Seems like less trouble... Thanks! – Boldewyn Jan 17 '11 at 21:40
  • You'll find once you've got the hang of apache config files the text editor is far more powerful than any management tool, and far more secure. – dunxd Jan 19 '11 at 21:16