Apache

http 的默認端口:80/tcp
https 的默認端口:443/tcp

http協議的版本:
http/0.9
http/1.0
http/1.1
http/2.0

socket:BSD是 socket ipc的一種實現,允許在不同的主機上的進程之間相互通信的解決方式
基於套接字有三中通信:
tcp套接字
udp套接字
裸套接字
套件字的使用格式
ipv4
ipv6
unix sock

工作的模式:
一次完整http事務:請求 -- 響應

URL 資源的標記 用於表示服務器上的資源的位置

資源的種類:
靜態資源:txt、jpg ...
動態資源:
服務器端:php jsp...
客戶端:.js

http請求的過程
1、建立或處理連接 接收或拒絕請求
2、接收請求 接收客戶端發來的請求報文
3、處理請求 對請求報文進行解析
4、訪問資源 通過存儲IO獲取用戶請求的資源
5、構建響應報文
6、發送響應報文
7、記錄於日誌中

http的併發響應模型:
單進程IO模型 串行響應
多進程IO模型 啓動多個進程 每個進程響應一個請求
複用Io模型 一個進程生成多個線程 每個線程響應一個請求

http請求處理的連接方式
保持連接:長連接 keepalive
非保持連接:短連接

httpd的特性:
高度模塊化的設計 核心(core) + modules
modules 支持動態裝載和卸載

支持MPM 
MPM:multipath processing modules  多路處理的模塊
  prefork:一個主進程,多個子進程,一個進程響應一個請求
    主進程:管理子進程,創建套接字 接收用戶請求,並派發給某子進程處理...
    子進程:處理、響應請求
  worker:多進程、多線程模型 一個線程響應一個請求; 
    主進程:管理子進程,創建套接字,接收用戶請求,並派發給某子進程處理...
    子進程:負責管理線程
    線程:處理並響應請求 
  event:事件驅動模型,多進程模型,每個進程響應多個請求;
    主進程:管理子進程,創建套接字,接收用戶請求,並派發給某子進程處理...
    子進程:處理並響應請求; 

httpd-2.2 event爲測試模式
    centos 6
httpd-2.4 可以在企業中正常使用
    centos 7

httpd的版本:
httpd-1.3 官方已經停止維護
httpd-2.0
httpd-2.2
httpd-2.4

官方網站:httpd.apache.org

安裝httpd:
rpm包、yum base源安裝:
編譯安裝:定製新功能、其他原因
centos 6 httpd-2.2
sysinit腳本 /etc/rc.d/sysinit.d/httpd
配置文件:
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
程序文件:
/usr/sbin/httpd
/usr/sbin/httpd.event
/usr/sbin/httpd.worker

     腳本配置文件:/etc/sysconfig/httpd
    日誌文件:/var/log/httpd  access_log 訪問日誌  error_log 錯誤日誌

centos 7 httpd-2.4
    systemd Unit file  /usr/lib/systemd/system/httpd.service

注意在做測試之間關閉iptables -F 防火牆
centos 6 httpd安裝:
yum -y install httpd
service httpd restart 啓動httpd 服務
chkconfig httpd on| off 開機自動啓動

ss -tnl 可以查看地址的80 端口是否開啓
LISTEN 0 128 :::80

可以用瀏覽器訪問一下本機的ip地址
會進入一個歡迎使用apache的頁面 說明沒有問題
這個歡迎頁面的程序在 /etc/httpd/conf.d 下的welcome.conf 這個文件

當把它改個名字 mv welcome.conf welcome.conf.bak
在重複一下服務器 service httpd reload
在測試就沒了 不過它會到/var/www/html/下去找文件

這是修改玩的測試頁面:
Index of /

[ICO]   Name    Last modified   Size    Description
Apache/2.2.15 (CentOS) Server at 172.20.10.4 Port 80

到/var/www/html/ 隨便編輯一些東西吧
vim /var/www/html/chenedu.html
hello chen

測試頁面沖刷一下
http://172.20.10.4/chenedu.html
hello chen

centos 7 httpd安裝:
yum -y install
程序環境:
配置文件:
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.modules.d/.conf
/etc/httpd/conf.d/
.conf
程序文件:
/usr/sbin/httpd
MPM支持DSO機制,所以各爲一個獨立的模塊;

日誌文件:
/var/log/httpd
access_log:訪問日誌
error_log:錯誤日誌
站點文檔根目錄:
/var/www/html
模塊文件路徑:
/usr/lib64/httpd/modules

systemctl restart httpd 啓動httpd服務

systemctl enable httpd 開機自動啓動

ss -tnl 查看80 端口
LISTEN 0 128 :::80

httpd—2.2的配置 centos 6
主配置文件: /etc/httpd/conf/httpd.conf
注意在修改配置文件之間先備份一下
cp -r httpd.conf httpd.conf.bak

在 /etc/httpd/conf/httpd.conf文件下的三種配置段
Section 全局配置
Section 1: Global Environment 全局的配置段

Section 2: 'Main' server configuration 中心服務器配置段

Section 3: Virtual Hosts 虛擬主機配置段

在修改httpd 的配置文件時
httpd -t 測試語法是否有問題
service httpd reload | restart

/etc/httpd/conf/httpd.conf 主文件配置的內容和修改定義:
1、修改的監聽的端口
Listen 80
Listen 8080 可以自己定義

2、持久連接: 說白了就是測試
tcp連接建立後,資源獲取完成不會斷開連接,會繼續等待請求資源
KeepAlive On|Off 如何斷開
MaxKeepAliveRequests 100 數量限制
KeepAliveTimeout 15 時間限制

用telnet請求測試:
[root@MiWiFi-R1CM-srv Packages]# telnet 192.168.31.176 80
Trying 192.168.31.176...
Connected to 192.168.31.176.
Escape character is '^]'.
GET /chenedu.html HTTP/1.1 GET:是請求方法 /chenedu.html:是資源 HTTP/1.1:協議的版本
Host:192.168.31.176 默認請求的地址

HTTP/1.1 200 OK
Date: Tue, 10 Jan 2017 15:24:06 GMT
Server: Apache/2.2.15 (CentOS)
Last-Modified: Mon, 30 May 2016 02:23:34 GMT
ETag: "3a0243-b-53405f178500e"
Accept-Ranges: bytes
Content-Length: 11
Connection: close
Content-Type: text/html; charset=UTF-8

hello chen

3、MPM 多路處理模塊
httpd-2.2的mpm不支持DSO機制 event爲測試
在centos6 上想使用其他的模塊的話 /etc/sysconfig/httpd 下
#HTTPD=/usr/sbin/httpd.worker | httpd.event 自己定義

/etc/httpd/conf/httpd.conf 模塊
prefork MPM 預先創建
<IfModule prefork.c>
StartServers 8 預先創建的空閒子進程
MinSpareServers 5 最小空閒進程
MaxSpareServers 20 最大空閒進程
ServerLimit 256 響應用戶進程的最大數量
MaxClients 256 服務器進程可以開始的最大數量
MaxRequestsPerChild 4000 限制最大的響應數量

worker MPM
<IfModule worker.c>
StartServers 4 初始啓動的進程數量 (子進程)
MaxClients 300 最大連接併發數量 (線程)
MinSpareThreads 25 最少空閒線程數量
MaxSpareThreads 75 最大空閒線程數
ThreadsPerChild 25 每個子進程啓動的線程
MaxRequestsPerChild 0 限制最大的響應數量 0:表示不做限制

4、DOS機制: 動態模塊裝載
LoadModule foo_module modules/mod_foo.so foo_modile 是文件

5、Main server 主服務器
如何定義一個主機:
有兩種方法:
1、編輯/etc/hosts下添加:
192.168.148.122 www.chenedu.com 我的本機ip地址 名稱可自己定義
2、直接編輯主配置文件/etc/httpd/conf/httpd.conf 添加:
ServerName www.cheneduo.com

6、站點資源訪問的路徑: 和上面5 一樣的
vim /var/www/html/index.html
<h1>index.html chenedu.com</h1>
可用用瀏覽器訪問自己的ip地址 即可

也可以自己創建一個目錄路徑: 在更改一下DocumentRoot 的資源訪問路徑 路徑是你創建的目錄路徑;

目錄中的常用指令:
(1) Options:用於定義資源的展示方式;後跟以空白字符分隔的“選項”列表;
Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews None All
Indexes:允許索引;
FollowSymLinks:允許跟蹤符號鏈接;
SymLinksifOwnerMatch:允許
ExecCGI:允許執行CGI腳本;

(2) AllowOverride None 一般不啓動

(3) order和allow/deny from 設置訪問允許、限制網段
IP地址的訪問控制;
示列:
Allow from 192.168.148.121 僅允許192.168.148.121 的主機訪問

order用於定義allow和deny的生效次序;
allow from IP/NETWORK/FQDN   
deny from IP/NETWORK/FQDN  網絡 域名
請求遵循最佳匹配法則機制
order  allow deny

7、定義站點主頁面
DirectoryIndex index.html index.html.var 從左邊開始搜索

8、定義路徑別名
alias

9、日誌
錯誤日誌:ErrorLog
ErrorLog logs/error_log /var/log/httpd/error_log
訪問日誌:
LogFormat:定義日誌信息的格式
CustomLog:指明日誌文件路徑和日誌格式
格式:
%h Remote host 遠程主機
%l Remote logname (from identd, if supplied) 用戶登錄使用的用戶名
%u Remote user (from auth; may be bogus if return status (%s) is 401) 用戶名
%t Time the request was received (standard english format) 服務器收到的請求時的時間
%r First line of request 請求報文的首行 起始行
%s Status. For requests that got internally redirected, this is the status of the original request --- %>s for the last. 記錄服務器在收到請求之後 根據客戶端的請求反映的狀態碼
%b Size of response in bytes, excluding HTTP headers 響應報文的大小 單位是字節
%i The contents of Foobar: header line(s) in the request sent to the server 請求報文的某個特定守護的值

10、用戶的訪問控制:

http協議的認證
認證質詢:
WWW-Authenticate:響應碼爲401,拒絕客戶端請求,說明要求客戶端提供賬號和密碼
認證:
Authorization:客戶端填入賬號和密碼後再次發送請求報文;認證通過後,服務端發送響應資源

虛擬的帳號:訪問服務的帳號和密碼
LoadModule

認證的方式:
basic 明文
digest 消息摘要認證

vim /var/www/html/admin/admin.html   創建/admin/admin.html 
 <h1>admin root</h1>
主頁面是:/var/www/html/index.html
index.html chenedu.com

下面basic認證 當訪問admin下的admin.html
編輯/etc/httpd/conf/httpd.conf 下創建一個安全域
<Directory "/var/www/html/admin"> Directory /var/www/html/admin 網站服務訪問的路徑:
Options None
AllowOverride None
AuthType basic 認證的類型
AuthName "For Administrators"
Authuserfile "/etc/httpd/conf/.httpdpasswd" 用戶的密碼、賬戶的文件
Require valid-user 允許那些人登錄
</Directory>

創建帳號文件:
 htpasswd -c -m /etc/httpd/conf/.httpdpasswd chen   創建chen 用戶
 New password: 
 Re-type new password: 

service httpd reload   重讀一下
現在可以用瀏覽器 測試了

要是組的帳號進行認證的話該怎麼做呢?
一、先創建一個安全域
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/admin">
Options None
AllowOverride None
AuthType basic
AuthName "For Administrators"
Authuserfile "/etc/httpd/conf/.httpdpasswd"
Authgroupfile "/etc/httpd/conf/.httpdgroup" 創建組的用戶、密碼等 文件 可自己定義
Require group groups 允許組中的用戶訪問
</Directory>

二、創建組的用戶和目錄 可自己定義
vim /etc/httpd/conf/.httpd.group
groups: user1 user2

htpasswd -m /etc/httpd/conf/.httpdpasswd user1
htpasswd -m /etc/httpd/conf/.httpdpasswd user2

service httpd reload 重讀一下即可 下面就可以測試

htpasswd
-c:創建文件;
-m:md5加密密碼;
-s: SHA加密密碼;
-D:刪除指定用戶

12、虛擬主機
站點標示:
ip相同,端口不同
ip不同,端口相同
FQDN不同
虛擬主機的三種實現方法:
ip的虛擬主機
每個虛擬主機使用獨有的ip地址

創建一個基於ip地址的虛擬主機
一、先創建ip地址:
ip addr add 192.168.148.100/16 dev eth0
inet 192.168.148.122/24 brd 192.168.148.255 scope global eth0
inet 192.168.148.100/32 scope global eth0

二、創建虛擬主機
可以參考/etc/httpd/conf/httpd.conf 最下面虛擬主機的配置
<VirtualHost *:80>

ServerAdmin [email protected]

DocumentRoot /www/docs/dummy-host.example.com

ServerName dummy-host.example.com

ErrorLog logs/dummy-host.example.com-error_log

CustomLog logs/dummy-host.example.com-access_log common

#</VirtualHost>

手動創建二個基於ip的虛擬主機:
第一個ip 地址 192.168.148.122
vim /etc/httpd/conf.d/vhost1.conf 可以自己定義的
<VirtualHost 192.168.148.122:80> 基於ip的地址
ServerName www1.chenedu.com 名稱
DocumentRoot /var/www/html/www1 網絡服務網頁

</VirtualHost>
第二個ip 地址 192.168.148.100
vim /etc/httpd/conf.d/vhost2.conf
<VirtualHost 192.168.148.100:80>
ServerName www2.chenedu.com
DocumentRoot /var/www/html/www2
</VirtualHost>

三、去創建網絡測試網頁
mkdir -pv /var/www/html/www{1,2}
mkdir: created directory /var/www/html/www1'<br/>mkdir: created directory/var/www/html/www2'

vim /var/www/html/www1/index.html
<h1>www1.chenedu.com</h1>

vim /var/www/html/www2/index.html
<h1>www2.chenedu.com</h1>

做完之後必須要檢測一下:
[root@chenedu ~]# httpd -t
Syntax OK

service httpd reload 重讀一下
下面可以用瀏覽器測試 :

端口(PORT)的虛擬主機:
每個虛擬主機使用一個獨有的端口(PORT)
創建基於端口的虛擬主機:
第一個不用修改
vim /etc/httpd/conf.d/vhost2.conf
<VirtualHost 192.168.148.122:8080> 改成原來的ip地址 8080 端口 可自己到/etc/httpd/conf/httpd.conf 定義端口 Listen 8080
ServerName www2.chenedu.com
DocumentRoot /var/www/html/www2
</VirtualHost>

httpd -t 檢測
service httpd reload 重讀

域名(FQDN)的虛擬主機:
每個虛擬主機使用一個獨有的域名(FQDN)
注意:虛擬主機和主服務器 不能同時使用

創建基於域名的虛擬主機:
現將/etc/httpd/conf/httpd.conf 下的NameVirtualHost *:80 打開 它默認是註釋 的
NameVirtualHost 192.168.148.122:80 當前本機的ip地址

vim /etc/httpd/conf.d/vhost1.conf
VirtualHost 192.168.148.122:80> 基於ip的地址
ServerName www1.chenedu.com 名稱
DocumentRoot /var/www/html/www1 網絡服務網頁
CustomLog logs/www1-access_log combined 訪問的日誌 在 /var/log/httpd
</VirtualHost>

vim /etc/httpd/conf.d/vhost2.conf
<VirtualHost 192.168.148.122:80>
ServerName www2.chenedu.com
DocumentRoot /var/www/html/www2
CustomLog logs/www2-access_log combined 訪問的日誌
</VirtualHost>

vim /etc/hosts
192.168.148.122 www1.chenedu.com www2.chenedu.com 其實可以在DNS下解析 就不用在這裏解析了
測試:
[root@chenedu ~]# curl http://www1.chenedu.com
<h1>www1.chenedu.com</h1>
[root@chenedu ~]# curl http://www2.chenedu.com
<h1>www2.chenedu.com</h1>
[root@chenedu ~]# curl http://192.168.148.122
<h1>www1.chenedu.com</h1>

httpd:
url:資源統一定位符
服務器地址:端口+ip地址

基本語法格式:
params:參數
http://www.chenedu.com/admin/admin.php;useranme=admin
query:查詢
http://www.magedu.com/admin/admin.php?logintime=10/12/2017
frag:
http://www.chenedu.com/admin/redme.html#ch1

httpd協議報文格式:
method:請求方法,客戶端希望服務器對資源執行的動作
GET:從服務器獲取一個資源

    HEAD:僅從服務器獲取資源響應的報文的首部

    POST:向服務器提交表單 表單就是把表單中的數據發送給服務器

status :響應狀態碼 
    請求處理過程的結果狀態

    顯示的結果提示:
    1xx 100-101:信息提示
    2xx 200-206:成功類的響應碼 如200
    3xx 300-305:重定向類的響應碼  如301, 302, 304...
    4xx 400-415:錯誤類信息客戶端錯誤  如 401, 404, 403...
    5xx 500-505:服務器端錯誤  如500,502...

headers:請求響應報文的首部
    首部分類:
      通用首部:請求、響應報文都可以使用

      請求首部
      響應首部
      實體首部
      擴展首部

httpd-2.2 基本配置:
一、status 頁面 啓用 status 頁面
vim /etc/sysconfig/httpd
HTTPD=/usr/sbin/httpd.worker 將它註釋掉 默認是註釋掉
service httpd restart 重啓

vim /etc/httpd/conf/httpd.conf  默認是註釋掉的
    <Location /server-status>
        SetHandler server-status    內部插件 啓用
        Order deny,allow        
        Deny from all   
        Allow from 192.168    
    </Location>
httpd -t 檢測語法

service httpd reload 重讀

用瀏覽器 訪問本機的ip地址
192.168.148.122/server-status 會顯示一下信息
Apache Server Status for 192.168.148.122

Server Version: Apache/2.2.15 (Unix) DAV/2
Server Built: Jul 24 2015 11:52:28
Current Time: Friday, 13-Jan-2017 19:06:16 CST
Restart Time: Wednesday, 01-Jun-2016 22:45:02 CST
Parent Server Generation: 1
Server uptime: 225 days 20 hours 21 minutes 14 seconds
1 requests currently being processed, 7 idle workers
_W______........................................................
................................................................
................................................................
................................................................
Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process

PID Key: 
   5056 in state: _ ,   5057 in state: W ,   5058 in state: _ 
   5059 in state: _ ,   5060 in state: _ ,   5061 in state: _ 
   5062 in state: _ ,   5063 in state: _ ,
To obtain a full report with current status information you need to use the ExtendedStatus On directive.

啓動 /etc/httpd/conf/httpd.conf
 ExtendedStatus On  將註釋# 去掉 
 service httpd reload
重新刷新一下頁面就多出更多的信息

二、user/group

指定用戶的身份運行httpd服務進程;
User apache
Group apache
可以用
ps aux  查看

三、mod_deflate模塊壓縮頁面優化傳輸速度
適用場景:
1、節約帶寬,額外消耗CPU;同時,可能有些較老瀏覽器不支持
2、壓縮適於壓縮的資源,例如文件文件

https:
SSL會話的簡化過程
(1) 客戶端發送可供選擇的加密方式,並向服務器請求證書;
(2) 服務器端發送證書以及選定的加密方式給客戶端;
(3) 客戶端取得證書並進行證書驗正:
如果信任給其發證書的CA:
(a) 驗正證書來源的合法性;用CA的公鑰解密證書上數字簽名;
(b) 驗正證書的內容的合法性:完整性驗正
(c) 檢查證書的有效期限;
(d) 檢查證書是否被吊銷;
(e) 證書中擁有者的名字,與訪問的目標主機要一致;
(4) 客戶端生成臨時會話密鑰(對稱密鑰),並使用服務器端的公鑰加密此數據發送給服務器,完成密鑰交換;
(5) 服務用此密鑰加密用戶請求的資源,響應給客戶端;

注意:SSL會話是基於IP地址創建;所以單IP的主機上,僅可以使用一個https虛擬主機;

創建一個私有CA認證 在爲服務端申請證書
192.168.148.121 當CA centos 7

一、先創建一個私有CA
cd /etc/pki/CA/ 先切到這個目錄下創建

[root@localhost CA]# (umask 077; openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
...............+++
.........+++
e is 65537 (0x10001)

在生成一個自簽證書
[root@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem
Country Name (2 letter code) [XX]:CN 國家
State or Province Name (full name) []:Shanghai 省的名字
Locality Name (eg, city) [Default City]:Shanghai 地方
Organization Name (eg, company) [Default Company Ltd]:ChenEdu 組織名
Organizational Unit Name (eg, section) []:Ops 組織單位名稱
Common Name (eg, your name or your server's hostname) []:ca.chenedu.com
Email Address []:[email protected] 郵箱

在多創建兩個文件 自己定義
touch index.txt
echo 01 > serial
私有CA 已創建完成

二、爲服務端申請證書:
192.168.148.122 centos 6
centos 6 上面默認是沒有mod_ssl 模塊
yum -y install mod_sll 安裝mod_sll
下面先創建一個私鑰文件
mkdir /etc/httpd/ssl
在ssl下創建私鑰
[root@www1 ssl]# (umask 077; openssl genrsa -out httpd.key 1024)
Generating RSA private key, 1024 bit long modulus
...++++++
...++++++
e is 65537 (0x10001)
注意:httpd.key的權限 最好是600

在生成簽署請求
[root@www1 ssl]# openssl req -new -key httpd.key -out httpd.csr
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Shanghai
Locality Name (eg, city) [Default City]:Shanghai
Organization Name (eg, company) [Default Company Ltd]:ChenEdu
Organizational Unit Name (eg, section) []:Ops
Common Name (eg, your name or your server's hostname) []:www1.chenedu.com
Email Address []:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

[root@www1 ssl]# scp httpd.csr 192.168.148.121:/tmp 將httpd.csr 複製到192.168.148.121 的tpm目錄下 進行簽署

在centos 7上:openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt 兩個y 就簽署成功了

在/etc/pki/CA/newcerts/ 會生成簽署的文件名爲 01.pem

再將文件複製回:scp certs/httpd.crt 192.168.148.122:/etc/httpd/ssl/ centos 6

vim /etc/httpd/conf.d/ssl.conf 啓用的配置文件
<VirtualHost default:443> 在下面的兩行
DocumentRoot "/var/www/html/www1" 路徑要用配置的虛擬主機上
ServerName www1.chenedu.com:443 虛擬主機的名稱及端口

Server Certificate: 服務器證書文件

Point SSLCertificateFile at a PEM encoded certificate. If

the certificate is encrypted, then you will be prompted for a

pass phrase. Note that a kill -HUP will prompt again. A new

certificate can be generated using the genkey(1) command.

SSLCertificateFile /etc/httpd/ssl/httpd.crt 創建證書的擺放路徑

Server Private Key: 服務器的私鑰文件

If the key is not combined with the certificate, use this

directive to point at the key file. Keep in mind that if

you've both a RSA and a DSA private key you can configure

both in parallel (to also allow the use of DSA ciphers, etc.)

SSLCertificateKeyFile /etc/httpd/ssl/httpd.key 創建私鑰的擺放路徑

在改完之後 :httpd -t 檢測語法
service httpd reload

ss -tnl 查看端口 443 是否啓用
下面測試即可;

用ab工具對httpd進行壓力測試:
ab
-n 總請求數
-c 模擬的併發數
-k 以持久連接模式 測試

上線之前做壓測 線上是絕對不能壓測的

httpd-2.4特性 centso 7
(1) MPM支持DSO機制,以模塊方式加載;
(2) event MPM生產可用;
(3) 異步讀寫機制;
(4) 支持每模塊及每目錄單獨日誌級別定義;
(5) 每請求相關的專用配置;
(6) 增強版的表達式分析器;
(7) 毫秒級的持久連接時長;
(8) 基於FQDN的虛擬主機不再需要專門的指令NameVirtualHost;
(9) 支持用戶自定義變量;
(10) 更低內在的開銷;

新模塊:
(1) mod_proxy_fcgi
(2) mod_proxy_scgi
(3) mod_remoteip

安裝centos 7的httpd
yum -y install httpd

主配置文件:
/etc/httpd/conf/httpd.conf
模塊配置文件:
/etc/httpd/conf.modules.d/.conf
分段配置文件:
/etc/httpd/conf.d/
.conf

選擇MPM 時用不同的模塊時
在/etc/httpd/conf.modules.d/00-mpm.conf 下選擇模塊

2、基於ip地址的訪問時:
和centos6 httpd-2.2 一樣 不過不支持allow deny. . .
允許所有主機訪問 Require all granted
拒絕所有主機訪問 Require all denied

vim /vat/www/html/index.html   測試頁面
<h1>Centos 7 httpd-2.4</h1>

如何拒絕物理主機的訪問
vim /etc/httpd/conf/httpd.conf
<RequireAll>
Require all granted
Require not ip 192.168.148.122 拒絕 192.168.148.122 這個主機訪問
</RequireAll>

httpd -t 檢測
systemctl reload httpd.service

在192.168.148.122 centos 6 的主機上可以測試
[root@www1 ~]# curl http://192.168.148.121/
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /
on this server.</p>
</body></html>

3、創建虛擬主機
FQDN的虛擬主機不再需要專門的指令NameVirtualHost;

vim /etc/httpd/conf.d/www1.conf 創建www1 的虛擬主機
<VirtualHost *:80>
ServerName www1.chenedu.com
DocumentRoot /var/www/html/www1
<Directory "/var/www/html/www1">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>

vim /etc/httpd/conf.d/www2.conf 創建www2 的虛擬主機
<VirtualHost *:80>
ServerName www2.chenedu.com
DocumentRoot /var/www/html/www2
<Directory "/var/www/html/www2">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>

mkdir -pv /var/www/html/www{1,2}

vim /var/www/html/www1/index.html 創建網站測試www1
<h1>www1.chenedu.com</h1>

vim /var/www/html/www1/index.html 創建網站測試www2
<h1>www2.chenedu.com</h1>

4、毫秒級長連接
KeepAlive
vim /etc/httpd/conf.d/keepalive 創建時間連接
KeepAlive On
KeepAliveTimeout 300ms 請求超時
MaxKeepAliveRequests 100 最大的請求數

httpd -t 檢測

systemctl reload httpd

5、https
和httpd-2.2 一樣一樣的

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章