I have an issue with serving a large amount of VirtualHosts and I was wondering if there is a more efficient way of doing things.
I’m currently using the Location directive to serve a large amount projects from different departments, over 300 projects from 19 departments in total. The structures is the same for every Location directive except for the directories the files are served from. What I currently have is a large file that looks something like this:
<VirtualHost *> ServerName www.myserver.com <Location /departmentA/project1> AuthType Basic AuthName 'By Invitation Only' AuthUserFile /usr/local/departmentA/project1/passwords Require valid-user </Location> <Location /departmentA/project2> AuthType Basic AuthName 'By Invitation Only' AuthUserFile /usr/local/departmentA/project2/passwords Require valid-user </Location> <Location /departmentB/project1> AuthType Basic AuthName 'By Invitation Only' AuthUserFile /usr/local/departmentA/project1/passwords Require valid-user </Location> </VirtualHost>
As you can see all these structures are the same except for the paths. What I would like is of course something where I can use variables for the department and project names and just maintain a single Location directive. I assume that this is also less heavy on the server and memory.
<VirtualHost *> ServerName www.myserver.com <Location /$1/$2> AuthType Basic AuthName 'By Invitation Only' AuthUserFile /usr/local/$1/$2/passwords Require valid-user </Location> </VirtualHost>
I don’t know of any way to do that specifically, as I don’t think
AuthUserFileaccepts a dynamic argument. It might be easiest to write a little script in your language of choice that takes a template for the<Location>block and repeats it for each directory you want to protect. Example, in Python:For each line of the form ‘departmentA/project1’ it reads on standard input, it prints out the corresponding
<Location>section.