学习Apache(三)

对某个目录开启验证登录

<Directory /var/www/html/admin >
    AllowOverride All
    Order allow,deny
    Allow from all
    AuthType Basic
    AuthName "hehe"
    AuthUserFile /etc/httpd/conf/htpasswd_file
    Require user admin
</Directory>

配置如下

 

 解释下

AuthName "hehet"                                 #此处为描述
AuthType Basic                                   #验证类型
AuthUserFile /etc/httpd/conf/htpasswd_file       #密码文件的路径

 然后执行命令把声明的密码放入配置文件中,这里第一个参数是用户名admin,第二个参数是密码

# htpasswd -bc /etc/httpd/conf/htpasswd_file admin admin

生成后的密码可以看到变成加密的了

# cat /etc/httpd/conf/htpasswd_file 
  admin:$apr1$PJMPb4wK$A/iGGSv4jgU2OAhcJsuhE.

多次执行显示的不一样

# cat /etc/httpd/conf/htpasswd_file
  admin:$apr1$PJMPb4wK$A/iGGSv4jgU2OAhcJsuhE.
# htpasswd -bc /etc/httpd/conf/htpasswd_file admin admin# cat /etc/httpd/conf/htpasswd_file
  admin:$apr1$pi1dWCyH$wBNx4bMNDTz1JnnSRc2Yq1
# htpasswd -bc /etc/httpd/conf/htpasswd_file admin admin# cat /etc/httpd/conf/htpasswd_file
  admin:$apr1$pJifA1Yz$tohiVP1dIjVNsXhWJCQJu1

 

  

 

posted on 2019-09-02 16:16  五光十色  阅读(185)  评论(0编辑  收藏  举报

导航