设为首页 收藏本站
查看: 903|回复: 0

[经验分享] 基于basic认证机制配置httpd服务器拥有用户访问控制功能

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-8-19 09:07:04 | 显示全部楼层 |阅读模式
实验须知:
    实验主机:192.168.1.11


1. 配置httpd基于用户的访问控制----basic认证机制

(1)安装httpd程序,并启动服务
1
2
3
4
5
#yum install httpd–y
[iyunv@node1 ~]# servicehttpd start
Starting httpd:httpd: Could not reliably determine the server's fully qualified domain name,using 172.16.33.1 for ServerName
                                                          [  OK  ]
[iyunv@node1 ~]# ss –tnl




(2)在配置文件中定义安全域

(a)修改’MainServer’的路径为/data/web/html,并进行访问测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#vim/etc/httpd/conf/httpd.conf
………….
DocumentRoot "/data/web/html"
.……..
# mkdir/data/web/html -pv
[iyunv@node1 ~]# cd/data/web/html/
[iyunv@node1 html]#vim index.html
添加:
           <h1>new path</h1>
         [iyunv@node1 ~]# httpd -t
httpd: Could not reliablydetermine the server's fully qualified domain name, using 172.16.33.1 forServerName
Syntax OK
[iyunv@node1 ~]# servicehttpd reload
Reloading httpd:



在浏览器中输入:http://192.168.1.11/,访问测试

(b)在/data/web/html/添加一个目录employee,并封装Directory,实现对此目录认证basic机制的实现,认证用户tom,jerry
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# mkdir/data/web/html/employee
# cd/data/web/html/employee
[iyunv@node1 employee]# vimindex.html
         Tom 21
         Jerry 90

#vim/etc/httpd/conf/httpd.conf
………添加Directory,对目录的访问控制…………
<Directory "/data/web/html/employee">
        Options None
        AllowOverride None
        AuthType basic
        AuthName "it is only foremployee!!"
        AuthUserFile /etc/httpd/users/.htpasswd
        Require user tom jerry
</Directory>
…………….
[iyunv@node1 html]# httpd-t
httpd: Could not reliablydetermine the server's fully qualified domain name, using 172.16.33.1 forServerName
Syntax OK





(3)创建/etc/httpd/users目录,并在目录下提供用户的账号文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[iyunv@node1 html]# mkdir/etc/httpd/users
[iyunv@node1 html]# cd/etc/httpd/users
[iyunv@node1 users]#htpasswd -c -m /etc/httpd/users/.htpasswd tom
New password:
Re-type new password:
Adding password for usertom
[iyunv@node1 users]#htpasswd  -m /etc/httpd/users/.htpasswdjerry
New password:
Re-type new password:
Adding password for userjerry
[iyunv@node1 users]# cat/etc/httpd/users/.htpasswd
tom:$apr1$snf79TuR$lX7b.Y8S9bbRtZh8cpbaz1
jerry:$apr1$sxqJzSiW$fa0WXYi2dFdCDIkO.0yCt1

         (4)重启服务,并在浏览器进行测试
                   [iyunv@node1 employee]# httpd-t
httpd: Could not reliablydetermine the server's fully qualified domain name, using 172.16.33.1 forServerName
Syntax OK
[iyunv@node1 employee]#service httpd reload
Reloading httpd:



此时在浏览器中输入:http://192.168.1.11/employee/,输入tom、jerry及对应密码,多次输入观察结果;发现只有tom、jerry用户且都要输入正确的密码才能成功访问!


2. 基于组的认证
创建组文件,并在配置文件中添加即可。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[iyunv@node1 employee]# vim /etc/httpd/conf/httpd.conf
…………修改为如下内容……………..

<Directory"/data/web/html/employee">
        Options None
        AllowOverride None
        AuthType basic
        AuthName "it is only foremployee!!"
        AuthUserFile /etc/httpd/users/.htpasswd
        AuthUserFile /etc/httpd/users/.htgroup
        Require group mc
</Directory>
………………………….
[iyunv@node1 employee]# vim/etc/httpd/users/.htgroup
………….添加如下内容……………….
           mc: tom jerry
[iyunv@node1 employee]#httpd -t
httpd: Could not reliablydetermine the server's fully qualified domain name, using 172.16.33.1 forServerName
Syntax OK
[iyunv@node1 employee]#service httpd reload
Reloading httpd:




基于组认证的配置就完成了,下面在浏览器中进行访问测试即可!!!!





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-100921-1-1.html 上篇帖子: http实现虚拟主机的配置 下篇帖子: 架设CA服务器实现https通信,web服务器使用CA自签证书与https通信 服务器 认证 用户
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表