Apache HTTP Server的源碼安裝配置及實現

來源:互聯網
上載者:User

標籤:伺服器   作業系統   基金會   linux   動態   

Apache HTTP Server簡介

Linux下最有名的、功能最豐富的WEB伺服器就屬Apache HTTP Server(簡稱Apache)。

Apache HTTP Server是Apache軟體基金會最有名的開源項目之一,它可以在大多數作業系統上運行。

目前官網的主要版本為2.2和2.4。CentOS 6使用2.2版本,CentOS 7使用2.4版本。

目前生產環境中部署2.2版本的居多,但是2.4版本有很多新的特性,下面就簡要說明以下:

(1)運行時動態可裝載MPM

在2.4版本中,MPM可以被編程成可裝載的模組。在運行時,只要配置使用什麼MPM即可。

(2)支援Event MPM

正式支援Event MPM,之前是作為實驗性的。

(3)更好的非同步讀寫支援

(4)在每模組及每目錄分別使用不同的記錄層級

(5)基於每一個請求可以使用<If>、<ElseIf>和<Else>配置

(6)增強版的運算式分析器

(7)可以毫秒級控制KeepAliveTimeout

(8)不再需要NameVirtualHost指令

(9)可以在配置中使用自訂變數

(10)比2.2版本使用更少的記憶體

(11)增加了很多新的Module,例如mod_proxy_fcgi, mode_ratelimit, mod_request, mod_remoteip。同時還增強了很多Module

(12)存取控制的改變

2.2 configuration:

Order deny,allow
Deny from all

2.4 configuration:

Require all denied

2.2 configuration:

Order allow,deny
Allow from all
2.4 configuration:

Require all granted

2.2 configuration:

Order Deny,Allow
Deny from all
Allow from example.org

2.4 configuration:

Require host example.org

鑒於V2.4引入了這麼多新的功能,生產環境安裝V2.4也是非常必要。

 

編譯安裝

準備工作

官網下載httpd-2.4.10.tar.bz2

實驗環境是CentOS 6.5,預設已經安裝了2.2版本,把V2.2停止掉。

[[email protected] named]# service httpd stop
[[email protected] named]# chkconfig httpd off
[[email protected] named]# chkconfig --list httpd
httpd              0:off    1:off    2:off    3:off    4:off    5:off    6:off
[[email protected] ~]# tar xf httpd-2.4.10.tar.bz2

apr安裝

httpd依賴apr(Apache Portable Runtime),且2.4版本依賴較新的apr版本,要求是1.4以上。CentOS 6安裝的是1.3.9

去http://apr.apache.org下載apr-1.5.1.tar.bz2和apr-util-1.5.3.tar.bz2。

[[email protected] ~]# tar xf apr-1.5.1.tar.bz2
[[email protected] ~]# tar xf apr-util-1.5.3.tar.bz2

[[email protected] ~]# cd apr-1.5.1

[[email protected] apr-1.5.1]# ./configure --prefix=/usr/local/apr15

[[email protected] apr-1.5.1]# make && make install

[[email protected] ~]# cd ~/apr-util-1.5.3

[[email protected] apr-util-1.5.3]# ./configure --prefix=/usr/local/aprutil15 --with-apr=/usr/local/apr15/

[[email protected] apr-util-1.5.3]# make && make install

安裝httpd

configure常用選項

名稱 說明 取值
--prefix 程式安裝目錄,預設安裝在/usr/local/apache2 /usr/local/apache24
--sysconfdir 設定檔目錄 /etc/httpd24
--enable-so 啟用DSO功能  
--enable-modules 空白字元分隔的module列表,也可以是"all" | "most" | "few" | "none" | "reallyall" most
--enable-ssl SSL/TLS支援(mod_ssl)  
--enable-cgi 支援CGI  
--enable-rewrite 伺服器端重寫  
--with-pcre 使用PCRE庫  
--with-apr 指定apr路徑 /usr/local/apr15/
--with-apr-util 指定apr-util路徑 /usr/local/aprutil15/
--with-z 使用zlib庫  
--enable-mpms-shared 空白字元分隔的MPM Module動態載入列表,可以是用all all
--with-mpm=MPM Apache使用的預設處理模型,MPM={event|worker|prefork|winnt} event

[[email protected] ~]# cd httpd-2.4.10
[[email protected] httpd-2.4.10]# ./configure --prefix=/usr/local/apache24 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-z --with-pcre --with-apr=/usr/local/apr15/ --with-apr-util=/usr/local/aprutil15/ --enable-mpms-shared=all --with-mpm=event --enable-modules=most
[[email protected] httpd-2.4.10]# make && make install

 

安裝目錄和檔案說明

/etc/httpd24 配置主目錄
/etc/httpd24/extra 額外配置目錄
/etc/httpd24/httpd.conf 主設定檔
/usr/local/apache24/htdocs 網站根目錄
/usr/local/apache24/error 預置的錯誤文檔目錄
/usr/local/apache24/cgi-bin CGI目錄
/usr/local/apache24/include 標頭檔目錄,二次開發用,必要時可以匯出
/usr/local/apache24/man 協助手冊,需要匯出
/usr/local/apache24/modules DSO模組目錄
/usr/local/apache24/bin 可執行檔目錄
/usr/local/apache24/logs 日誌目錄

匯出bin目錄

[[email protected] ~]# cd /etc/profile.d/
[[email protected] profile.d]# vim httpd24.sh
PATH=/usr/local/apache24/bin:$PATH
export PATH

然後重啟串連會話

匯出man目錄

在/etc/man.config 中加入一條

MANPATH /usr/local/apache24/man

即可生效

匯出標頭檔目錄

[[email protected] /]# ln -s /usr/local/apache24/include/ /usr/include/apache

apachectl

apachectl是/usr/local/apache24/bin下的一個shell指令碼。通過它可以控制httpd的啟動、關閉、重啟、優雅重啟動、優雅關閉。

所謂優雅,就是不蠻橫,重啟或者關閉前如果有串連就不會立即終止串連。

第一次嘗試啟動

[[email protected] ~]# apachectl start

[[email protected] ~]# ss -tnlp | grep :80
LISTEN     0      128                      :::80                      :::*      users:(("httpd",2308,4),("httpd",2309,4),("httpd",2310,4),("httpd",2311,4))

[[email protected] ~]# httpd -D DUMP_MODULES
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
mpm_event_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)

瀏覽器測試一下

650) this.width=650;" title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="http://img1.51cto.com/attachment/201408/10/6716920_1407678526xQNw.png" "660" height="380" />

 

實驗

虛擬機器主機

server-status

基於使用者的存取控制

HTTPS

未完待續……

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.