Apache文件服务器采用用户名和密码认证

1、安装apache服务

[root@177de8178558 /]# yum install httpd -y

2、编辑配置文件

[root@177de8178558 /]# vim /etc/httpd/conf/httpd.conf
添加
<Directory "/var/www/html/test">
     Options Indexes
     AllowOverride AuthConfig
     Order allow,deny
     Allow from all  
</Directory>

创建密码文件

[root@177de8178558 /]# vim /var/www/html/test/.htaccess
AuthName "sys"
AuthType Basic
AuthUserFile /var/www/html/test/.htpasswd
require user test

第一行,验证提示信息。
第二行,验证类别。
第三行,密码文件所在路径,绝对路径。
第四行,指定登录用户名。指定admin用户登录。

创建密码文件

[root@177de8178558 /]# htpasswd -c /var/www/html/test/.htpasswd test
注:第二次添加用户名不需要加-c参数了

4、启动服务

[root@177de8178558 /]# systemctl start httpd

5、验证

发表评论

后才能评论