在CentOS 7上安裝Apache Web伺服器



本章我們將簡要了解Apache HTTP伺服器的背景,然後在CentOS Linux 7上安裝最新的穩定版本。

Apache Web伺服器簡史

Apache是一個存在已久的Web伺服器。事實上,幾乎與http本身一樣久遠!

Apache最初是國家超級計算應用中心(也稱為NCSA)的一個小型專案。在90年代中期,“httpd”(當時的名稱)是網際網路上最流行的Web伺服器平臺,市場份額約為90%或更多。

當時,這是一個簡單的專案。熟練的IT人員(稱為網站管理員)負責:維護Web伺服器平臺和Web伺服器軟體,以及前端和後端網站開發。httpd的核心是它能夠使用稱為外掛或擴充套件的自定義模組。網站管理員也足夠熟練,可以編寫核心伺服器軟體的補丁。

在90年代中期後期,httpd的首席開發人員和專案經理離開了NCSA去做其他事情。這使得最流行的web-daemon處於停滯狀態。

由於httpd的使用如此廣泛,一群經驗豐富的httpd網站管理員呼籲召開一次關於httpd未來的峰會。會議決定協調並應用最好的擴充套件和補丁到當前的穩定版本中。然後,當前的http伺服器鼻祖誕生了,並被命名為Apache HTTP Server。

鮮為人知的歷史事實 - Apache並非以某個美國土著部落的戰士命名。事實上,它的命名帶有一定的巧妙之處:它是由許多才華橫溢的計算機科學家提供的許多修復程式(或補丁)組成的:一個充滿補丁的Apache

在CentOS Linux 7上安裝當前穩定版本

步驟1 - 透過yum安裝httpd。

yum -y install httpd

此時,Apache HTTP伺服器將透過yum安裝。

步驟2 - 根據您的httpd需求編輯httpd.conf檔案。

在預設的Apache安裝中,Apache的配置檔名為httpd.conf,位於/etc/httpd/中。因此,讓我們在vim中開啟它。

vim中開啟的httpd.conf的前幾行 -

# 
# This is the main Apache HTTP server configuration file.  It contains the 
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information. 
# In particular, see  
# <URL:http://httpd.apache.org/docs/2.4/mod/directives.html> 
# for a discussion of each configuration directive.

我們將進行以下更改,以允許我們的CentOS安裝從http埠80提供http請求。

監聽主機和埠

# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

在這裡,我們將Apache更改為監聽特定埠或IP地址。例如,如果我們想在備用埠8080上執行httpd服務。或者如果我們的Web伺服器配置了多個具有單獨IP地址的介面。

監聽

阻止Apache將每個監聽守護程式附加到每個IP地址上。這對於停止僅指定IPv6或IPv4流量很有用。甚至繫結到多宿主主機上的所有網路介面。

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
Listen 10.0.0.25:80
#Listen 80

DocumentRoot

“文件根目錄”是Apache在訪問您的伺服器時查詢要為請求服務的索引檔案的預設目錄:http://www.yoursite.com/ 將檢索並提供來自您的文件根目錄的索引檔案。

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"

步驟3 - 啟動並啟用httpd服務。

[root@centos rdc]# systemctl start httpd && systemctl reload httpd 
[root@centos rdc]#

步驟4 - 配置防火牆以允許訪問埠80請求。

[root@centos]# firewall-cmd --add-service=http --permanent
廣告