码迷,mamicode.com
首页 > Web开发 > 详细

web服务_apache配置(3)v1.0

时间:2016-09-19 22:33:34      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:apache

 

11、基于用户的访问控制                    

       认证质询:

              WWW-Authenticate:响应码为401,拒绝客户端请求,并说明要求客户端提供账号和密码;                    

       认证:

              Authorization:客户端用户填入账号和密码后再次发送请求报文;认证通过时,则服务器发送响应的资源;

                                  

              认证方式有两种:

                     basic:明文

                     digest:消息摘要认证

                           

       安全域:需要用户认证后方能访问的路径;应该通过名称对其进行标识,以便于告知用户认证的原因;

                           

       用户的账号和密码存放于何处?

              虚拟账号:仅用于访问某服务时用到的认证标识

                                  

              存储:(tttpd要有相应的是配模块)

                     文本文件;

                     SQL数据库;

                     ldap目录存储;(读性能超级好 写性能超级差)

                           

       basic认证配置示例:

              (1) 定义安全域

                     <Directory "">

                            Options None

                            AllowOverride None

                            AuthType Basic    基于Basci 认证

                            AuthName "String  安全预提示信息

                            AuthUserFile  "/PATH/TO/HTTPD_USER_PASSWD_FILE"  文件

                            Require  user  username1  username2 ...(valid-user)

                     </Directory>

                                         

                     允许账号文件中的所有用户登录访问:

                            Require  valid-user

                                         

              (2) 提供账号和密码存储(文本文件)

                     使用专用命令完成此类文件的创建及用户管理

                            htpasswd  [options]   /PATH/TO/HTTPD_PASSWD_FILE  username

                                   -c:自动创建此处指定的文件,因此,仅应该在此文件不存在时使用;

                                   -m:md5格式加密

                                   -s: sha格式加密

                                   -D:删除指定用户

                                                       

              另外:基于组账号进行认证;

                     (1) 定义安全域

                            <Directory "">

                                   Options None

                                   AllowOverride None

                                   AuthType Basic

                                   AuthName "String

                                   AuthUserFile  "/PATH/TO/HTTPD_USER_PASSWD_FILE"

                                   AuthGroupFile "/PATH/TO/HTTPD_GROUP_FILE"

                                   Require  group  grpname1  grpname2 ...

                            </Directory>

                                                

                     (2) 创建用户账号和组账号文件;

                                                

                            组文件:每一行定义一个组 vim编辑即可

                                   GRP_NAME: username1  username2  ...

                                                                            

12、虚拟主机

                    

       站点标识: socket

              IP相同,但端口不同;

              IP不同,但端口均为默认端口;

              FQDN不同;

                     请求报文中首部

                     Host: www.magedu.com

                                         

       有三种实现方案:

              基于ip:

                     为每个虚拟主机准备至少一个ip地址;

              基于port:

                     为每个虚拟主机使用至少一个独立的port;

              基于FQDN:

                     为每个虚拟主机使用至少一个FQDN;

                    

       注意:一般虚拟机不要与中心主机混用;因此,要使用虚拟主机,得先禁用‘main‘主机;

              禁用方法:注释中心主机的DocumentRoot指令即可;

                                  

       虚拟主机的配置方法:

              <VirtualHost  IP:PORT>  虚拟主机 ip:端口

                     ServerName FQDN              虚拟主机的FQDN

                     DocumentRoot  ""              目录

              </VirtualHost>

                                  

              其它可用指令:

                     ServerAlias:虚拟主机的别名;可多次使用;

                     ErrorLog:

                            CustomLog:

                     <Directory "">

                     ...

                     </Directory>

                     Alias

                     ...

                                         

              基于IP的虚拟主机示例:

              <VirtualHost 172.16.100.6:80>

                     ServerName www.a.com

                     DocumentRoot "/www/a.com/htdocs"

              </VirtualHost>

 

              <VirtualHost 172.16.100.7:80>

                     ServerName www.b.net

                     DocumentRoot "/www/b.net/htdocs"

              </VirtualHost>

 

              <VirtualHost 172.16.100.8:80>

                     ServerName www.c.org

                     DocumentRoot "/www/c.org/htdocs"

              </VirtualHost>

                                  

              基于端口的虚拟主机:

              <VirtualHost 172.16.100.6:80>

                     ServerName www.a.com

                     DocumentRoot "/www/a.com/htdocs"

              </VirtualHost>

 

              <VirtualHost 172.16.100.6:808>

                     ServerName www.b.net

                     DocumentRoot "/www/b.net/htdocs"

              </VirtualHost>

 

              <VirtualHost 172.16.100.6:8080>

                     ServerName www.c.org

                     DocumentRoot "/www/c.org/htdocs"

              </VirtualHost>

                                  

              基于FQDN的虚拟主机:

              NameVirtualHost 172.16.100.6:80

 

              <VirtualHost 172.16.100.6:80>

                     ServerName www.a.com

                     DocumentRoot "/www/a.com/htdocs"

              </VirtualHost>

 

              <VirtualHost 172.16.100.6:80>

                     ServerName www.b.net

                     DocumentRoot "/www/b.net/htdocs"

              </VirtualHost>

 

              <VirtualHost 172.16.100.6:80>

                     ServerName www.c.org

                     DocumentRoot "/www/c.org/htdocs"

              </VirtualHost>                                                                            

                                                              

13、status页面

       LoadModule  status_module  modules/mod_status.so

                           

       <Location /server-status>

              SetHandler server-status

              Order allow,deny

              Allow from 172.16

       </Location>


web服务_apache配置(3)v1.0

标签:apache

原文地址:http://zx337954373.blog.51cto.com/11323677/1854226

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!