Hi Emanuele,2016-09-12 12:42 GMT+02:00 Emanuele Bastianelli <manu.reeko@xxxxxxxxx>:I'm using Apache 2.4 with
mod_macro
. According to the documentation, it is possible to instantiate several macro, in order to not to rewrite the same block of configuration. Example from the documentation:<Macro VHost $name $domain> <VirtualHost *:80> ServerName $domain ServerAlias www.$domain DocumentRoot "/var/www/vhosts/$name" ErrorLog "/var/log/httpd/$name.error_lo
g" CustomLog "/var/log/httpd/$name.access_l og" combined </VirtualHost> </Macro> Use VHost example example.com Use VHost myhost hostname.org Use VHost apache apache.org
I did the same for my server, with the following
VirtualHost
configuration file <Macro VHost $request_uri> <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined DBDriver mysql DBDParams "host=localhost port=3306 user=myself pass=myselfpass dbname=apacheauth" DBDMin 2 DBDKeep 4 DBDMax 10 DBDExptime 300 <Location $request_uri> AuthName $request_uri AuthType Digest AuthDigestAlgorithm MD5 AuthDigestDomain / AuthDigestProvider dbd AuthDBDUserRealmQuery "SELECT MD5(password) FROM password WHERE username = %s AND realm = %s" Require valid-user </Location> </VirtualHost> </Macro> Use VHost /test Use VHost /anothertest
The prolem is that the configuration work when I try to access
www.mysite.com/test
, asking me for the credential, and does not work when I try to accesswww.mysite.com/anothert
, showing me the current page without asking the credential. It seems like the server instantiates aest VirtualHost
only for the first Use directive, skipping all the following.I would try using the Macro directive only for the Location one, like this:<Macro RestrictedURI $request_uri><Location $request_uri>AuthName $request_uriAuthType DigestAuthDigestAlgorithm MD5AuthDigestDomain /AuthDigestProvider dbdAuthDBDUserRealmQuery "SELECT MD5(password) FROM password WHERE username = %s AND realm = %s"Require valid-user</Location></Macro>Use RestrictedURI /testUse RestrictedURI /anothertestI am not super expert with mod_macro but it seems that you are duplicating the VirtualHost rather than the Location blocks only.Hope it helps!Luca