日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

详述CentOS 7中Apache配置与应用(一)

發布時間:2023/12/1 综合教程 38 生活家
生活随笔 收集整理的這篇文章主要介紹了 详述CentOS 7中Apache配置与应用(一) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

系統運維

Apache連接保持
Apache連接保持相關參數

KeepAlive

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

KeepAlive\' Timeout

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

MaxKeepAliveRequests

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

Apache訪問控制

作用

控制對網站資源的訪問
為特定的網站目錄添加訪問授權

常用訪問控制方式

客戶機地址限制
用戶授權限制

基于客戶端地址的訪問控制

使用Require配置項實現訪問控制,按先后順序限制

可用于<Location>、<Directory>、<Files>、 <Limit>配置段中

Require配置項的常見語法

Require all granted
Require all denied
Require local
Require [not] host <主機名或域名列表>
//使用not禁止訪問時要將其置于<RequireAll> </RequireAll>容器中并在容器中指定相應的限制策略
Require [not] ip <IP地址或網段列表>

配置實例

Linux系統中安裝dns、HTTP服務,并設置DNS服務。

[root@localhost ~]# yum install bind httpd -y   //安裝服務
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
...//省略部分內容...
已安裝:
  bind.x86_64 32:9.11.4-9.P2.el7                    httpd.x86_64 0:2.4.6-90.el7.centos 
...//省略部分內容...  
完畢!
[root@localhost conf]# vim /etc/named.conf    //編輯DNS配置文件
...//省略部分內容...
options {
        listen-on port 53 { any; };            //更改IP地址為any
        listen-on-v6 port 53 { ::1; };
        directory       /var/named;
        dump-file       /var/named/data/cache_dump.db;
        statistics-file /var/named/data/named_stats.txt;
        memstatistics-file /var/named/data/named_mem_stats.txt;
        recursing-file  /var/named/data/named.recursing;
        secroots-file   /var/named/data/named.secroots;
        allow-query     { any; };             //更改監聽主機為any
...//省略部分內容... 
:wq
[root@localhost conf]# vim /etc/named.rfc1912.zones     //編輯區域配置文件
...//省略部分內容...
zone kgc.com IN {                      //更改域名
        type master;
        file kgc.com.zone;         //更改區域數據文件名
        allow-update { none; };
};
...//省略部分內容...
:wq
[root@localhost conf]# cd /var/named/           //進入區域數據文件目錄
[root@localhost named]# ls                     //查看目錄
data  dynamic  named.ca  named.empty  named.localhost  named.loopback  slaves
[root@localhost named]# cp -p named.localhost kgc.com.zone     //復制區域數據文件
[root@localhost named]# vim kgc.com.zone               //進入編輯文件
$TTL 1D 
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
www IN  A       192.168.144.133                   //設置域名解析
:wq                                        //保存退出

開啟兩臺win 10客戶機,并查看客戶機IP地址

在Linux系統中進入http服務站點目錄,編輯主頁內容,并開啟DNS、HTTP服務,關閉防火墻及增強性安全功能

[root@localhost named]# cd /var/www/html/    //進入http服務站點目錄
[root@localhost html]# vim index.html             //編輯默認主頁
<h2>this is kgc web</h2>             //編輯內容
:wq
[root@localhost html]# ls           //查看
index.html              
[root@localhost html]# cat index.html    //查看網頁內容
<h2>this is kgc web</h2>
[root@localhost html]# systemctl start httpd.service         //啟動http服務
[root@localhost html]# systemctl start named                   //啟動DNS服務
[root@localhost html]# systemctl stop firewalld.service         //關閉防火墻
[root@localhost html]# setenforce 0                            //關閉增強性安全功能

使用兩臺win 10客戶機分別訪問往網站信息,看服務是否正常提供

在Linux系統中配置HTTP服務配置文件,設置客戶機訪問權限

[root@localhost html]# vim /etc/httpd/conf/httpd.conf  
//編輯主配置文件內容(現網中不建議直接修改主配置文件內容,可以重新添加子配置文件進行限制)
...//省略部分內容...
<Directory /var/www/html>
    #
    # Possible values for the Options directive are None, All,
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that MultiViews must be named *explicitly* --- Options All
    # doesn\'t give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be All, None, or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
     <RequireALL>                          //在此容器下添加子容器
       Require not ip 192.168.144.128             
       //添加限制訪問主機的IP地址(如若限制網段直接添加192.168.144.0/24即可,注意限制網段需填寫子網掩碼)
       Require all granted
    </RequireALL>
</Directory>
...//省略部分內容...
:wq
[root@localhost html]# systemctl restart httpd.service 

查看限制的第一臺win 10客戶端是否還可以訪問網站

用戶授權限制
配置實例

創建用戶認證數據庫

[root@localhost html]# htpasswd -c /etc/httpd/conf/pwd test01  
//創建用戶認證數據庫(-c為創建,如果已經存在數據認證文件可以不用-c,直接就可以使用命令添加進認證文件中)
New password:               //輸入設置的密碼
Re-type new password:         //再次輸入密碼
Adding password for user test01  //成功創建
[root@localhost html]# cd /etc/httpd/conf        //進入目錄
[root@localhost conf]# ls        //查看
httpd.conf  magic  pwd            //成功創建文件
[root@localhost conf]# cat pwd     //查看文件內容
test01:$apr1$zDZ/54yz$rUCXaWixaltHE6ZBvjv0h/    //創建的用戶及密碼

添加用戶授權配置

[root@localhost conf]# vim httpd.conf
...//省略部分內容...
<Directory /var/www/html>
    #
    # Possible values for the Options directive are None, All,
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that MultiViews must be named *explicitly* --- Options All
    # doesn\'t give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be All, None, or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
   AuthName DocumentRoot                      //更改上面的訪問控制條目,此條目聲明驗證信息
   AuthType Basic                               //驗證類型為基本驗證
   AuthUserFile /etc/httpd/conf/pwd             //驗證文件路徑
   Require valid-user                           //設置為授權用戶驗證
</Directory>
...//省略部分內容...
:wq                                          //保存退出
[root@localhost conf]# systemctl restart httpd.service  //重新啟動服務

在客戶機中驗證配置

總結

以上是生活随笔為你收集整理的详述CentOS 7中Apache配置与应用(一)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。