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
生成后的密码可以看到变成加密的了
[root@linux-node2 proc]# cat /etc/httpd/conf/htpasswd_file admin:$apr1$PJMPb4wK$A/iGGSv4jgU2OAhcJsuhE. [root@linux-node2 proc]#
多次执行显示的不一样
[root@linux-node2 proc]# cat /etc/httpd/conf/htpasswd_file admin:$apr1$PJMPb4wK$A/iGGSv4jgU2OAhcJsuhE. [root@linux-node2 proc]# htpasswd -bc /etc/httpd/conf/htpasswd_file admin admin Adding password for user admin [root@linux-node2 proc]# cat /etc/httpd/conf/htpasswd_file admin:$apr1$pi1dWCyH$wBNx4bMNDTz1JnnSRc2Yq1 [root@linux-node2 proc]# htpasswd -bc /etc/httpd/conf/htpasswd_file admin admin Adding password for user admin [root@linux-node2 proc]# cat /etc/httpd/conf/htpasswd_file admin:$apr1$pJifA1Yz$tohiVP1dIjVNsXhWJCQJu1 [root@linux-node2 proc]#