不能实现 “网站的拥有者并不希望直接将网页内容显示出来,而只想让通过身份验证的用户看到里面的内容,这时就可以在网站中添加密码功能”

第1步:先使用htpasswd命令生成密码数据库。-c参数表示第一次生成;后面再分别添加密码数据库的存放文件,以及验证要用到的用户名称(该用户不必是系统中已有的本地账户)。

[root@linuxprobe ~]# htpasswd -c /etc/httpd/passwd linuxprobe
New password:此处输入用于网页验证的密码
Re-type new password:再输入一遍进行确认
Adding password for user linuxprobe

第2步:继续编辑个人用户主页功能的配置文件。把第31~37行的参数信息修改成下列内容,其中以井号(#)开头的内容为添加的注释信息,可将其忽略。随后保存并退出配置文件,重启httpd服务程序即可生效。

[root@linuxprobe ~]# vim /etc/httpd/conf.d/userdir.conf
………………省略部分输出信息………………
 27 #
 28 # Control access to UserDir directories.  The following is an example
 29 # for a site where these directories are restricted to read-only.
 30 #
 31 <Directory "/home/*/public_html">
 32     AllowOverride all 
        #刚刚生成出的密码验证文件保存路径
 33     authuserfile "/etc/httpd/passwd" 
        #当用户访问网站时的提示信息
 34     authname "My privately website"
        #验证方式为口令模式
 35     authtype basic
        #访问网站时需要验证的用户名称
 36     require user linuxprobe
 37 </Directory>
[root@linuxprobe ~]# systemctl restart httpd

但未出现相应效果

在这里插入图片描述

解决方法重启

Guess you like

Origin blog.csdn.net/qq_52835624/article/details/121295874