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”,可以看到需要输入密码
做了一个Linux学习的平台,目前出来一个雏形,各位可以参考使用
链接:https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ 密码:n7bk
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29270124/viewspace-2221044/
,如需转载,请注明出处,否则将追究法律责任。