jlthlx 发表于 2018-11-19 07:35:44

Apache配置讲解——用户认证

  有时候我们有这样的需求:有一个网站,其中一个目录只有你自己或者管理员才能看到的,不想让别人去访问,而且,还想在网站去展示,因为方便自己访问,这时候,有必要去做一个用户认证。也就是当你输入用户名和密码之后,只有输入正确了才可以去访问。
  ## 假如网站下有abc目录,目录有个文件,正常的话,可以访问
  # mkdir abc
  # cp /etc/passwd abc/123.txt
http://note.youdao.com/yws/res/3482/WEBRESOURCE825ac94f3dce19e615d5a6a60555b65f
  ## 但比如说我们不想让别人访问网站下的abc目录,这时要做用户认证,编辑虚拟主机配置文件
  # vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
     
        AllowOverride AuthConfig
        AuthName "auth-admin"
        AuthType Basic
        AuthUserFile /data/.htpasswd
        require valid-user
     
http://note.youdao.com/yws/res/3487/WEBRESOURCE5849178af196d8ed464c3856cc4b59b9
  # /usr/local/apache2/bin/apachectl -t
  Syntax OK
  # /usr/local/apache2/bin/apachectl graceful
  ## 创建密码文件
  # /usr/local/apache2/bin/htpasswd -c /data/.htpasswd wyy
  New password:
  Re-type new password:
  Adding password for user wyy
  ## 查看生成的密码
  # cat /data/.htpasswd
  wyy:U6opizopWbwsg
  ## 查看帮助文档
  # /usr/local/apache2/bin/htpasswd --help
   -cCreate a new file.
   -nDon't update file; display results on stdout.
   -mForce MD5 encryption of the password.
   -dForce CRYPT encryption of the password (default).
   -pDo not encrypt the password (plaintext).
   -sForce SHA encryption of the password.
   -bUse the password from the command line rather than prompting for it.
   -DDelete the specified user.
  # 再次创建用户,则不需要-c创建密码文件,否则会覆盖
  # /usr/local/apache2/bin/htpasswd -m /data/.htpasswd wyy1
  New password:
  Re-type new password:
  Adding password for user wyy1
  # 修改配置文件测试语法
  # /usr/local/apache2/bin/apachectl -t
  Syntax OK
  #重启
  #/usr/local/apache2/bin/apachectl restart
  ## 这时候呢,再访问这个abc目录话,就需要输入用户名与密码
http://note.youdao.com/yws/res/3495/WEBRESOURCEa38df89dee74723d05d07eced21d5958
  




页: [1]
查看完整版本: Apache配置讲解——用户认证