Linux服务器---apache支持用户认证

Apache支持用户认证
      为了服务器的安全,通常用户在请求访问某个文件夹的时候,Apache可以要求用户输入有效的用户名和登录密码

1、创建一个测试目录
      [root@localhost cgi-bin]#  mkdir /var/www/html/wj

2、开启认证功能,修改配置文件httpd.conf如下,(将html目录的配置中none改为all) 
      [root@localhost ~]# gedit /etc/httpd/conf/httpd.conf
      <Directory "/var/www/html">
      # AllowOverride controls what directives may be placed in .htaccess files.
      # It can be "All", "None", or any combination of the keywords:
      #   Options FileInfo AuthConfig Limit
      #
           AllowOverride All          //默认是none,这里改为all
      #
      # Controls who can get stuff from this server.
      #
           Order allow,deny
           Allow from all
      </Directory>

3、给需要认证的目录添加配置,修改httpd.conf文件,添加如下内容
      <Directory "/var/www/html/wj">     //wj就是我们要认证的目录
          AllowOverride AuthConfig       //这里必须使用AuthConfig
          Order allow,deny
          Allow from all
      </Directory>


4、 给测试目录设置用户名和密码
      [root@localhost wj]#  htpasswd -c /var/www/html/wj/.htpasswd david      //david就是创建的用户名
      New password:                 //这里需要输入密码,下面的是确认密码
      Re-type new password: 
      Adding password for user david      //创建成功
      [root@localhost wj]# 

5、创建htaccess文件,并且增加内容 
      [root@localhost wj]#  vim .htaccess
       AuthUserFile /var/www/html/wj/.htpasswd
      AuthName "david"
      AuthType Basic
      require valid-user


6、重启Apache服务
      [root@localhost wj]#  service httpd restart

7、测试,在浏览器输入“127.0.0.1/wj”,可以看到需要输入密码
      
      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值