Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache: One setting for multiple directories

I'd like to protect multiple directories with mod_digest with one settings.

Currently I have this /etc/apache2/conf.a/mod-digest_realm-protected.conf

AuthType Digest
AuthName "protected"
AuthDigestDomain /adminer/ /school-project/
AuthDigestNonceLifetime 300

AuthDigestProvider file
AuthUserFile /etc/apache2/.digest
Require valid-user

and this in /etc/apache/sites-available/default

<Directory /var/www/adminer/>
     Include /etc/apache2/conf.a/mod-digest_realm-protected.conf
</Directory>

<Directory /var/www/school-project/>
     Include /etc/apache2/conf.a/mod-digest_realm-protected.conf
</Directory>

Is there a way to have this setting in a single config file? I tried something like this

<Directory /var/www/(adminer/school-project)/>
   ... auth_digest settings
</Directory>

but it doesn't work.

like image 809
Hologos Avatar asked Jun 12 '13 21:06

Hologos


People also ask

What is IfModule in Apache?

<IfModule> is simply a directive that tests the condition "is the named module loaded by apache httpd" (in your example mod_expires). It allows people to produce conditional based configuration for different installations where certain modules may be present or not.

What is the main difference between location and directory sections?

The usage is straightforward - you would use Location if you need to fine tune access rights by an URL, and you would use Directory if you need to control access rights to a directory (and its subdirectories) in the filesystem.

What is ServerRoot in Apache configuration?

ServerRoot. The ServerRoot directive specifies the top-level directory containing website content. By default, ServerRoot is set to "/etc/httpd" for both secure and non-secure servers.


2 Answers

try this

<Directory /var/www/>
   ... auth_digest settings
</Directory>

Regex can be used with Directory directive.
http://httpd.apache.org/docs/current/en/mod/core.html#directory

If you just want to protect some of them, I think this should work.

<Directory ~ "(adminer|school-project)"/>
   ... auth_digest settings
</Directory>
like image 87
Sacry Avatar answered Sep 29 '22 14:09

Sacry


DirectoryMatch also works

<DirectoryMatch ^/var/www/(adminer|school-project)>
...
</DirectoryMatch>
like image 31
Ray Chakrit Avatar answered Sep 29 '22 14:09

Ray Chakrit