配置apache密码认证

apache提供了一系列的认证,授权,访问控制模块,我们这里选用最方便的mod_auth_basic,mod_authn_file,mod_authz_user这三个模块实现目录或文件需要输入用户和密码认证。
1、生成密码文件
示例:

  1. htpasswd -c /var/www/.htpasswd centos

/var/www/.htpasswd是密码文件的位置
centos是添加授权的用户
htpasswd工具详细使用说明:http://lamp.linux.gov.cn/Apache/ApacheMenu/programs/htpasswd.html
2、配置httpd.conf文件

  1. <directory /var/www/html/centos>
  2. AuthType basic
  3. AuthBasicProvider file
  4. AuthUserFile /var/www/.htpasswd
  5. Require valid-user
  6. </directory>

这里是当访问centos目录时需要认证。
参考:http://lamp.linux.gov.cn/Apache/ApacheMenu/howto/auth.html

标签:Apache 发布于:2019-11-23 20:28:59