You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Emanuele Bastianelli <ma...@gmail.com> on 2016/09/12 10:42:06 UTC
[users@httpd] Apache 2.4 mod_macro does not instantiate all the defined Macros
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.
Best
EB
Re: [users@httpd] Apache 2.4 mod_macro does not instantiate all the
defined Macros
Posted by Emanuele Bastianelli <ma...@gmail.com>.
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 <to...@gmail.com>:
> Hi Emanuele,
>
> 2016-09-12 12:42 GMT+02:00 Emanuele Bastianelli <ma...@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
>
>
Re: [users@httpd] Apache 2.4 mod_macro does not instantiate all the
defined Macros
Posted by Luca Toscano <to...@gmail.com>.
Hi Emanuele,
2016-09-12 12:42 GMT+02:00 Emanuele Bastianelli <ma...@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