apache 通过mod_auth模块能设置用户验证功能,具体有两个步骤
1、生成密码文件,文件中包含用户名和密码,默认密码是md5编码的
比如在/usr/share/monitorix目录下运行
sudo htpasswd -cb .passwd monitorix 123456
会创建一个.passwd的文件,文件里面存储了用户名monitorix和md5加密的密码
2、为目录配置用户验证功能
比如要配置/usr/share/monitorix,在http.conf中添加如下配置
-
Alias /monitorix /usr/share/monitorix
-
-
<Directory "/usr/share/monitorix">
-
Options Indexes Includes FollowSymLinks
-
Order Deny,Allow
-
Deny from All
-
Allow from 127.0.0.1
-
AllowOverride None
-
AuthUserFile /usr/share/monitorix/.passwd
-
#AuthGroupFile /dev/null
-
AuthName "Monitorix: Restricted access, sorry."
-
AuthType Basic
-
Require valid-user
-
# Satisfy Any
-
</Directory>
Alias /monitorix /usr/share/monitorix
<Directory "/usr/share/monitorix">
Options Indexes Includes FollowSymLinks
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
AllowOverride None
AuthUserFile /usr/share/monitorix/.passwd
#AuthGroupFile /dev/null
AuthName "Monitorix: Restricted access, sorry."
AuthType Basic
Require valid-user
# Satisfy Any
</Directory>
然后重启apache服务
访问 http://127.0.0.1/monitorix 就会弹出一个用户登录验证的密码框
(责任编辑:IT) |