天天看點

伺服器群集——Apache連接配接保持、通路控制與身份驗證一、Apache連接配接保持二、基于用戶端位址的通路控制三、使用者授權限制四、實驗

Apache通路控制與身份驗證

  • 一、Apache連接配接保持
    • Apache連接配接保持相關參數
  • 二、基于用戶端位址的通路控制
  • 三、使用者授權限制
    • 1、建立使用者認證資料庫
    • 2、使用者授權限制
  • 四、實驗
    • 1、連接配接保持
    • 2、通路控制
    • 3、身份驗證,使用者授權驗證

一、Apache連接配接保持

Apache連接配接保持相關參數

1、KeepAlive

  • 是否打開連接配接保持,OFF關閉,ON打開

    2、KeepAlive Timeout

    一次連接配接多次請求之間的最大間隔時間, 兩次請求超過該時間連接配接斷開

    3、MaxKeepAliveRequests

  • 一次長連接配接能夠傳輸的最大請求數量

    直接在配置檔案裡面改

    伺服器群集——Apache連接配接保持、通路控制與身份驗證一、Apache連接配接保持二、基于用戶端位址的通路控制三、使用者授權限制四、實驗
    伺服器群集——Apache連接配接保持、通路控制與身份驗證一、Apache連接配接保持二、基于用戶端位址的通路控制三、使用者授權限制四、實驗
    在虛拟主機中改
    伺服器群集——Apache連接配接保持、通路控制與身份驗證一、Apache連接配接保持二、基于用戶端位址的通路控制三、使用者授權限制四、實驗

二、基于用戶端位址的通路控制

  • 使用Require配置項實作通路控制,按先後順序限制
  • 可用于、、 、 配置段中
  • Require配置項的常見文法

    Require all granted

    Require all denied

    Require local

    Require [no0] host <主機名或域名清單>

    Require inog ip <IP位址或網段清單>

    使用not禁止通路時要将其置于 容器中并在容器中指定相應的限制政策

    伺服器群集——Apache連接配接保持、通路控制與身份驗證一、Apache連接配接保持二、基于用戶端位址的通路控制三、使用者授權限制四、實驗

三、使用者授權限制

1、建立使用者認證資料庫

[[email protected] ~]# cd /usrlocal/httpd/
[[email protected] httpd]# bin/htpasswd -c /usrlocalhttpd/conf/ .awspwd      //建立密碼檔案    -c建立使用,再次建使用者則不需要
webadmin
New password:
Re-type new password:
Adding password for user webadmin
[[email protected] httpd]# cat /usr/localhttpd/conf/.awspwd      //确認使用者資料庫檔案
webadmin:$apr1$L53Ws/Y2$3L4xhs4zZKDbJb.9p1fNg.
           

2、使用者授權限制

1、添加使用者授權配置

[[email protected] ~ ]# vim /tc/ttpd/conf/httpd.conf
...
<Directory "/usrlocal/httpd/htdocs">
...
AuthName "DocumentRoot"    //受保護的領域名稱
AuthType Basic   //認證類型
AuthUserFile /etc/httpd/conf/ .awspwd    //使用者認證賬号檔案
Require valid-user   //要求通過認證才能通路
</Directory>
[[email protected] ~ ]# systemctl restart httpd
           
伺服器群集——Apache連接配接保持、通路控制與身份驗證一、Apache連接配接保持二、基于用戶端位址的通路控制三、使用者授權限制四、實驗

四、實驗

1、連接配接保持

[[email protected] ~]# yum -y install httpd bind
[[email protected] ~]# vim /etc/httpd/conf/httpd.conf 
KeepAlive on
KeepAlive Timeout 600
也可以放虛拟主機中
[[email protected] ~]# vim /etc/httpd/conf/extra/vhost.conf
<VirtualHost *:80>
    DocumentRoot "/var/www/html/kgc"
    ServerName www.kgc.com
    ErrorLog "logs/www.kgc.com.error_log"
    CustomLog "logs/www.kgc.com.access_log" common
    KeepAlive on                          //開啟連接配接保持
    KeepAlive Timeout 600                 //斷開連接配接保持,設定連接配接逾時
    <Directory "/var/www/html">
        Require all granted
    </Directory>
</VirtualHost>
           

2、通路控制

基于用戶端位址通路控制

[[email protected] extra]# vim vhost.conf    //虛拟主機配置檔案(基于IP)見上個部落格web虛拟機
<VirtualHost 192.168.200.110:80>
    DocumentRoot "/var/www/html/kgc"
    ServerName www.kgc.com
    ErrorLog "logs/www.kgc.com.error_log"
    CustomLog "logs/www.kgc.com.access_log" common
    <Directory "/var/www/html">
        <RequireALL>                                   // ************
        Require not ip 192.168.200.233 // 僅拒絕,也可以是網段Require not ip 192.168.200.0/24 
        Require all granted
        </RequireALL>                                  // 一定要加标簽**********
    </Directory>
</VirtualHost>
[[email protected] extra]# systemctl restart httpd
浏覽器清理緩存
192.168.200.110  登入不上設定網站
192.168.200.130  可以登入上網站
           

3、身份驗證,使用者授權驗證

htpasswd -c 密碼檔案路徑 使用者名

[[email protected] extra]# which htpasswd 
/usr/bin/htpasswd
[[email protected] extra]# htpasswd -c /etc/httpd/conf/pwd jerry
New password:                                                 //設定密碼abcd1234
Re-type new password:                                    //設定密碼abcd1234
Adding password for user jerry
[[email protected] extra]# cd /etc/httpd/conf
[[email protected] conf]# ls
extra  httpd.conf  magic  pwd
[[email protected] conf]# cat pwd 
jerry:$apr1$R84Tljf5$sNAHos4sTerMyfO1shDzX0
[[email protected] conf]# pwd
/etc/httpd/conf                              //檢視所在位置
[[email protected] conf]# vim extra/vhost.conf 
<VirtualHost 192.168.200.130:80>
    DocumentRoot "/var/www/html/kgc02"
    ServerName www.kgc.com
    ErrorLog "logs/www.kgc02.com.error_log"
    CustomLog "logs/www.kgc02.com.access_log" common
    <Directory "/var/www/html">
        AuthName "DocumentRoot"                           //#####添加這幾句話
        AuthType basic                                   //#####
        AuthUserFile /etc/httpd/conf/pwd                  //#####
        Require valid-user                                //#####
    </Directory>
</VirtualHost>
[[email protected] conf]# systemctl restart httpd     //重新開機服務
去浏覽器清空記錄,并登陸192.168.200.130
輸入賬号jerry
密碼abcd1234