Apache用户认证

   

11.18Apache用户认证

002UASMrzy7605pjKJv15&690.jpg

 

修改虚拟主机配置文件/usr/local/apache/conf/extra/httpd-vhosts.conf

<Directory/data/wwwroot/abc.com>
AllowOverrideAuthConfig
AuthName"123.comuserauth"
AuthTypeBasic
AuthUserFile/data/.htpasswd
requirevalid-user
</Directory>

<Directory/data/wwwroot/abc.com>#指定认证的目录
AllowOverrideAuthConfig#这个相当于打开认证的开关
AuthName"123.comuserauth"#自定义认证的名字,作用不大
AuthTypeBasic#认证的类型,一般为Basic
AuthUserFile/data/.htpasswd#指定密码文件所在位置
requirevalid-user#指定需要认证的用户为全部可用用户
</Directory>

/usr/local/apache/bin/htpasswd-c-m/data/.htppasswdlxylxy//设置密码文件

Options:
-c:=create,创建一个加密文件
-n:不更新加密文件,只将更新后的用户名密码显示在屏幕上
-m:使用MD5算法对密码进行加密(默认)
-d:使用CRYPT算法对密码进行加密
-p:不对密码进行加密,即明文密码
-s:使用SHA算法对密码进行加密
-b:在命令行一并输入用户名和密码,而不是根据提示输入密码
-D:删除指定用户

对网站中指定文件设置用户认证

<FilesMatch123.php>#改成FilesMatch标签
AllowOverrideAuthConfig#这个相当于打开认证的开关
AuthName"123.comuserauth"#自定义认证的名字,作用不大
AuthTypeBasic#认证的类型,一般为Basic
AuthUserFile/data/.htpasswd#指定密码文件所在位置
requirevalid-user#指定需要认证的用户为全部可用用户
</Directory>

<FilesMatch123.php>
AllowOverrideAuthConfig
AuthName"123.comuserauth"
AuthTypeBasic
AuthUserFile/data/.htpasswd
requirevalid-user
</Directory>