
我正在尝试设置基于基本 apache2 身份验证的身份验证系统。为此,我将 mod_authn_dbd 配置为使用如下所示设置的 mysqli 数据库:https://www.howtoforge.de/anleitung/passwort-geschutzte-verzeichnisse-auf-apache2-mit-mod_auth_mysql-debian-squeeze/。
接下来,我像这样设置我的 site.conf:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/html
ServerName exmpl.de
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
DBDriver mysql
DBDParams "dbname=db user=usr pass=pass"
DBDMin 4
DBDKeep 8
DBDMax 20
DBDExptime 300
<Directory "/var/www/html">
# mod_authn_core and mod_auth_basic configuration
# for mod_authn_dbd
AuthType Basic
AuthName "Users only"
# To cache credentials, put socache ahead of dbd here
AuthBasicProvider socache dbd
# Also required for caching: tell the cache to cache dbd lookups!
AuthnCacheProvideFor dbd
AuthnCacheContext my-server
# mod_authz_core configuration
Require valid-user
# mod_authn_dbd SQL query to authenticate a user
AuthDBDUserPWQuery "SELECT passwd FROM mysql_auth WHERE username = %s"
</Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
它对我的数据库非常有效:
create table mysql_auth (
username varchar(255) not null,
passwd varchar(255),
groups varchar(255),
primary key (username)
);
现在我想增加使特定文件夹及其内容仅对特定组的用户可用的可能性,因此我添加了:
<Directory "/var/www/html/folder1/folder2">
# mod_authn_core and mod_auth_basic configuration
# for mod_authn_dbd
AuthType Basic
AuthName group specific area
AuthBasicProvider dbd
# mod_authn_dbd SQL query to authenticate a logged-in user
AuthDBDUserPWQuery \
"SELECT password FROM mysql_auth WHERE username = %s"
# mod_authz_core configuration for mod_authz_dbd
Require dbd-group groupname
# mod_authz_dbd configuration
AuthzDBDQuery "SELECT groups FROM mysql_auth WHERE user = %s"
</Directory>
(https://httpd.apache.org/docs/current/mod/mod_authz_dbd.html)重新启用 site.conf 并尝试重新启动 apache2 后,我收到此消息:
Mar 23 23:31:12 v*** apachectl[1665]: AH00526: Syntax error on line 70 of /etc/apache2/sites-enabled/site.conf:
Mar 23 23:31:12 v*** apachectl[1665]: Unknown Authz provider: dbd-group
甚至“需要组 groupname”也不起作用。我真的不知道我做错了什么。有什么想法吗?
提前致谢。
答案1
我发现了我的错误:我没有“a2enmod authz_dbd”