httpd title

topic

1, the establishment httpd service requirements:
(1) provide two name-based virtual hosting:
www1.stuX.com, page file directory / web / vhosts / www1; the error log to / var / log / httpd / www1 / error_log access log is / var / log / httpd / www1 / access_log;
www2.stuX.com, page file directory / web / vhosts / www2; the error log to / var / log / httpd / www2 / error_log, access log is / var / log / the httpd / www2 / access_log;
(2) outputs state information www1.stuX.com/server-status, and requires only allows users access to account;
(. 3) allowed www1 network 192.168.1.0/24 the host access;

2, for the top 2 virtual hosts provide https services, enabling users to access this web site via https security;
(1) requires certificate authentication, the certificate requires the use of the National (CN), the state (Beijing), city ( beijing), organization (jzbg);
(2) set the department called www2.stuX.com as Ops, the host;

reference

Reference: https://www.cnblogs.com/jzbgltb/p/10051124.html
Reference: http://uee.me/bh4Gh
Reference: https://blog.51cto.com/shumao/1826349?source=dra
reference : https://www.cnblogs.com/jiesying/p/7710888.html

Experimental summary

1, based virtual hosting, configured with two virtual machine host, do not use the domain name hosts resolved, monitor port 80 in all local IP or IP's.
2, by www1.stuX.com/server-status outputs a status information is added LOCATION,

13、status页面
    LoadModule  status_module  modules/mod_status.so

    httpd-2.2
        <Location /server-status>
            SetHandler server-status
            Order allow,deny
            Allow from 172.16
        </Location>

    httpd-2.4
        <Location /server-status>
            SetHandler server-status
            <RequireAll>
                Require ip 172.16
            </RequireAll>
        </Location> 

3, restricting access to resources

11、基于用户的访问控制

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

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

        认证方式有两种:
            basic:明文 
            digest:消息摘要认证

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

    用户的账号和密码存放于何处?
        虚拟账号:仅用于访问某服务时用到的认证标识

        存储:
            文本文件;
            SQL数据库;
            ldap目录存储;

    basic认证配置示例:
        (1) 定义安全域
            <Directory "">
                Options None
                AllowOverride None
                AuthType Basic
                AuthName "String“
                AuthUserFile  "/PATH/TO/HTTPD_USER_PASSWD_FILE"
                Require  user  username1  username2 ...
            </Directory>

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

        (2) 提供账号和密码存储(文本文件)
            使用专用命令完成此类文件的创建及用户管理
                htpasswd  [options]   /PATH/TO/HTTPD_PASSWD_FILE  username 
                    -c:自动创建此处指定的文件,因此,仅应该在此文件不存在时使用;
                    -m:md5格式加密
                    -s: sha格式加密
                    -D:删除指定用户
                    -b:批模式添加用户 
                        htpasswd -b  [options]   /PATH/TO/HTTPD_PASSWD_FILE  username password

        另外:基于组账号进行认证;
            (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) 创建用户账号和组账号文件;

                组文件:每一行定义一个组
                    GRP_NAME: username1  username2  ...

4, different network host access restrictions

站点访问控制常见机制

可基于两种机制指明对哪些资源进行何种访问控制

    文件系统路径:
        <Directory  "">
        ...
        </Directory>

        <File  "">
        ...
        </File>

        <FileMatch  "PATTERN">
        ...
        </FileMatch>
    URL路径:
        <Location  "">
        ...
        </Location>

        <LocationMatch "PATTERN">
        ...
        </LocationMatch>

<Directory>中“基于源地址”实现访问控制:

    httpd-2.2:

         order和allow、deny
            order:定义生效次序;写在后面的表示默认法则;

            Allow from, Deny from
                来源地址:
                    IP
                    NetAddr:
                        172.16
                        172.16.0.0
                        172.16.0.0/16
                        172.16.0.0/255.255.0.0

    httpd-2.4:
        基于IP控制:
            Require ip  IP地址或网络地址
            Require not ip IP地址或网络地址
        基于主机名控制:
            Require host 主机名或域名
            Require not host 主机名或域名

        要放置于<RequireAll>配置块中或<RequireAny>配置块中;

    控制页面资源允许所有来源的主机可访问:
        httpd-2.2
            <Directory "">
                ...
                Order allow,deny
                Allow from all 
            </Directory>

        httpd-2.4
            <Directory "">
                ...
                Require all granted
            </Directory>    

    控制页面资源拒绝所有来源的主机可访问:
        httpd-2.2
            <Directory "">
                ...
                Order allow,deny
                Deny from all 
            </Directory>

        httpd-2.4
            <Directory "">
                ...
                Require all denied
            </Directory>    

    Options:Configures what features are available in a particular directory
        后跟1个或多个以空白字符分隔的“选项”列表;
            Indexes:指明的URL路径下不存在与定义的主页面资源相符的资源文件时,返回索引列表给用户;
            FollowSymLinks:允许跟踪符号链接文件所指向的源文件;
            None:
            All:All options except for MultiViews.

5, status page

13、status页面
    LoadModule  status_module  modules/mod_status.so

    httpd-2.2
        <Location /server-status>
            SetHandler server-status
            Order allow,deny
            Allow from 172.16
        </Location>

    httpd-2.4
        <Location /server-status>
            SetHandler server-status
            <RequireAll>
                Require ip 172.16
            </RequireAll>
        </Location> 

Guess you like

Origin blog.51cto.com/14012942/2437979