auth_basic_module 的应用
创建http用户
-- 基于用户
cd /etc/httpd/conf.d/
htpasswd -c .authfile zs
htpasswd .authfile ls
-- 基于组
cd /etc/httpd/conf.d/
vim .httpgroup
g1: zs ls
g2: ww zl
htpasswd -c .authfile zs
htpasswd .authfile ls
htpasswd .authfile ww
htpasswd .authfile zl
创建目录、主页面
mkdir /var/www/html/admin
echo admin > /var/www/html/admin/index.html
配置文件
-- 基于用户
vim /etc/httpd/conf.d/test.conf
<Directory "/var/www/html/admin">
authtype basic
authname "admin path"
authuserfile "/etc/httpd/conf.d/.authfile"
require user zs // requre valid-user
</Directory>
-- 基于用户 或者用下面这个配置也可以
vim /var/www/html/admin/.htaccess
authtype basic
authname "admin path"
authuserfile "/etc/httpd/conf.d/.authfile"
vim /etc/httpd/conf.d/test.conf
<Directory "/var/www/html/admin">
allowoverride authconfig
</Directory>
-- 基于组
vim /etc/httpd/conf.d/test.conf
<Directory "/var/www/html/admin">
authtype basic
authname "admin path"
authuserfile "/etc/httpd/conf.d/.authfile"
authgroupfile "/etc/httpd/conf.d/.httpgroup"
require group g1
</Directory>
启动服务
httpd -t
systemctl restart httpd
测试

htpasswd 命令
htpasswd [options] /PATH/HTTPD_PASSWD_FILE username
-c 自动创建文件,仅应该在文件不存在时使用
-p 明文密码
-d CRYPT格式加密,默认
-m md5格式加密
-s sha格式加密
-D 删除指定用户
本文详细介绍如何使用auth_basic_module模块实现基于用户和组的HTTP认证。包括使用htpasswd命令创建http用户,配置Apache服务来限制对特定目录的访问,以及通过不同方式验证用户身份。
3172

被折叠的 条评论
为什么被折叠?



