0

I'm looking for a way to organize the files that makes up the apache sites-enabled configuration.

Let's say I have sites A, B and C on my webserver. These sites have different DocumentRoot s and different RewriteRule s as well as different Authentication requirements. Defined by Alias and Directory contexts. I'm on a debian based server.

I want both a http and https version of A, B and C.

For VirtualHost ServerName www1.myhome.com;, I want to serve A and B.

For VirtualHost ServerName www2.myhome.com;, I want to serve B and C.

How do I avoid duplication of the configuration of A, B and C?

I was trying to use includes in different forms. Including configuration for e.g. A into the different virtualhosts, but I found the problem with file paths cumbersome. In particular it doesn't allow me to a2ensite A. Also it makes troubleshooting the configuration file a nuisance. This is all done as a part of migrating from Apache2.2 to Apache2.4.

Is there a good solution to this problem?

Configuration site A. B and C are similar in structure.

Alias /A /srv/rootA/ <Directory /srv/rootA/> // Unique stuff for A // In particular Auth and rewrite rules </Directory> 
1
  • By "sites" I do you mean Virtual Hosts or just three directories? Commented Sep 17, 2014 at 8:45

1 Answer 1

2

It's one solution amongst many and I'm assuming you're on a debian based server.

In your apache serverroot directory, create a directory instances. In this directory create as many config files as you have "sites" (A,B or C). Define in them what you need to and name each file accordingly.

In sites-available directory, create one file for each virtual host you need. In these files, define you virtual host as usual and include "sites" config as needed, ie:

# Vhost for www1.myhome.com <VirtualHost *:80> Include instances/siteA.conf Include instances/siteB.conf </VirtualHost> 

After, you'll be able to do a2ensite and debug easier.

Ref on Apache include command : http://httpd.apache.org/docs/2.4/mod/core.html#include

3
  • Thanks this is useful. How would I go about to a2ensite siteA.conf? Commented Sep 17, 2014 at 16:33
  • You won't, siteX.conf aren't seen as "sites" from apache POV. You'll do a2ensite on files present in sites-available directory. Commented Sep 18, 2014 at 7:38
  • I'm able to put instances in sites-available and a2ensite instances/siteA. The command works but gives warnings. Not sure if I'll go that route though. Thanks for your insights. Commented Sep 18, 2014 at 15:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.