生成用户、密码文件:
htpasswd -c /etc/httpd/passwd user
1.直接编辑Apache配置添加认证:
#https://www.haiyun.me
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
AuthName "Httpd Access"
AuthType Basic
AuthUserFile /etc/httpd/passwd
Require valid-user
</Directory>
2.以.htaccess认证,首先授权相应网站建.htaccess验证权限:
Options Indexes FollowSymLinks
AllowOverride AuthConfig
Order allow,deny
Allow from all
在验证目录新建.htaccess文件:
AuthName "Httpd Access"
AuthType Basic
AuthUserFile /etc/httpd/passwd
Require valid-user