前提条件
1、阿帕奇服务安装完成
参考:Redhat 9 搭建Apache服务-CSDN博客
环境
Redhat 9
步骤:
通过userdir模块,共享目录资料
创建用户
[root@admin ~]# useradd DL
[root@admin ~]# passwd DL
更改用户 DL 的密码 。
新的密码:
无效的密码: 密码是一个回文
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
[root@admin ~]#
创建用户目录并授权以及index.html文件
html代码获取地址:总结了一些 html(H5) 各种 炫酷代码_h5代码-CSDN博客
[root@admin ~]# mkdir /home/DL/public_html
[root@admin ~]# chmod 711 /home/DL/
[root@admin ~]# chmod 755 /home/DL/public_html/
[root@admin ~]# vim /home/DL/public_html/index.html
[root@admin ~]#
修改userdir模块配置文件
重启服务验证是否以启用
[root@admin ~]# vim /etc/httpd/conf.d/userdir.conf
17 # UserDir disabled //注释掉这一行
18
19 #
20 # To enable requests to /~user/ to serve the user's public_html
21 # directory, remove the "UserDir disabled" line above, and uncomment
22 # the following line instead:
23 #
24 UserDir public_html //启用这一行
25 </IfModule>
[root@admin ~]# systemctl restart httpd.service
访问测试 ip/~用户名/
增加登录用户
htpasswd命令是建立和更新存储用户名、密码的文本文件, 用于对HTTP用户的basic认证。
[root@admin ~]# htpasswd -c /etc/httpd/passwd DL
New password:
Re-type new password:
Adding password for user DL
增加登录认证配置、重启服务
注释掉原有的三行、增加如下配置
[root@admin ~]# vim /etc/httpd/conf.d/userdir.conf
31 <Directory "/home/*/public_html">
32 # AllowOverride FileInfo AuthConfig Limit Indexes
33 # Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
34 # Require method GET POST OPTIONS
35 AllowOverride all //允许的相关指令
36 authuserfile "/etc/httpd/passwd" //验证登录密码的路径
37 authname "欢迎光临!" //信息提示
38 authtype basic //密码类型
39 require user DL //指定的登录用户
40 </Directory>
[root@admin ~]# systemctl restart httpd.service
浏览器测试 ip/~用户名/
登录成功!