httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emanuele Bastianelli <manu.re...@gmail.com>
Subject Re: [users@httpd] Apache 2.4 mod_macro does not instantiate all the defined Macros
Date Mon, 12 Sep 2016 18:20:08 GMT
Yeah, I ended up with basically the same solution.
In the macro.conf file under conf-enabled/ I put

<Macro RestrictedURI $request_uri>
    <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>
</Macro>

Then, under the sites-enabled/ dir, in the 000-default.conf, I put

Use RestrictedURI /test
Use RestrictedURI /anothertest

and it worked.

Thanks!

PS: watch out that in the AuthDBDUserRealmQuery the call to the MD5
function is wrong. I write this for whoever will read this thread in the
future.

2016-09-12 12:23 GMT+01:00 Luca Toscano <toscano.luca@gmail.com>:

> Hi Emanuele,
>
> 2016-09-12 12:42 GMT+02:00 Emanuele Bastianelli <manu.reeko@gmail.com>:
>
>> I'm using Apache 2.4 with mod_macro. According to the documentation
>> <https://httpd.apache.org/docs/2.4/mod/mod_macro.html>, 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_log"
>>     CustomLog "/var/log/httpd/$name.access_log" 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 access www.mysite.com/anothertest, showing me the current
>> page without asking the credential. It seems like the server instantiates a
>> VirtualHostonly 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_uri
>           AuthType Digest
>           AuthDigestAlgorithm MD5
>           AuthDigestDomain /
>           AuthDigestProvider dbd
>           AuthDBDUserRealmQuery "SELECT MD5(password) FROM password WHERE
> username = %s AND realm = %s"
>           Require valid-user
>     </Location>
> </Macro>
>
> Use RestrictedURI /test
> Use RestrictedURI /anothertest
>
> I 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
>
>

Mime
View raw message