版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cx55887/article/details/85796646
在http基于域名的虚拟主机的实现博文中有配置jd首页,这篇博文就实现,在访问jd首页的时候需要输入账号密码才能访问。本片博文是博文apache配置文件httpd.conf----小白福利中配置18:基于用户的访问控制的案例。
1、修改httpd的配置文件
<VirtualHost *:80>
DocumentRoot /var/www/html/jd/
ServerName www.jd.com
Directoryindex index.html
ErrorLog /var/www/html/jd/logs/error.log
CustomLog /var/www/html/jd/logs/access.log common
<Directory />
options None
AllowOverRide AuthConfig <<< 指定基于用户做访问控制
AuthType Basic <<< 指定认证方式
AuthName "wellcome to login jd..." <<< 输入欢迎信息,要求输入帐号密码
AuthBasicProvider file <<< 指定密码文件保存方式
AuthUserFile /etc/httpd/conf/.htpwd <<< 指定保存密码文件的位置
Require user zhangsan lisi <<< 指定哪些用户可以登录系统
</Directory>
</VirtualHost>
2、创建密码文件
创建密码文件的命令:`htpasswd`
格式:htpasswd [-c -m] 密码文件 用户名
选项:
-c:创建密码文件(如果文件已经存在了,那么-c会清空原始文件,然后重新创建)
-m:用md5加密数据
[root@web2 ~]# htpasswd -c -m /etc/httpd/conf/.htpwd zhangsan
[root@web2 ~]# htpasswd -m /etc/httpd/conf/.htpwd lisi
[root@web2 ~]# htpasswd -m /etc/httpd/conf/.htpwd wangwu
[root@web2 ~]# tail /etc/httpd/conf/.htpwd
zhangsan:$apr1$OmThiVWD$YfZwKY/TPeTzyQBCTI7vE.
lisi:$apr1$i6ydkUAp$hgBw0o.IuNAmqIC2HnD05.
wangwu:$apr1$8.SNk9Km$B.o83nHTeESK9NV8bC52/0
3、在浏览器访问 www.jd.com,如下图就需要输入账号密码才能进入。
------做运维之前很矫情的小年轻-----