apache 用户登录认证

前提条件

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/~用户名/

登录成功!

  • 19
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值