本文配置环境:centos
分两个步骤
第一:创建一个密码文件
htpasswd -cm /etc/httpd/.htpasswd 用户名
会有一个输入密码的提示,创建密码
然后修改apache配置文件,增加:
<Directory "/var/www/html/authdir"> AuthName "xxxx" #取名 AuthType basic #设定为基础认证 AuthUserFile /etc/httpd/.htpasswd #指定密码文件 Require Vali-user #打开密码功能 </Directory>
然后创建目录,重启apache服务即可