Linux Admin 简明教程

Install Apache Web Server CentOS 7

在本章中,我们将讲述一些 Apache HTTP Server 如何诞生的背景,然后在 CentOS Linux 7 上安装最新稳定版本。

In this chapter, we will learn a little about the background of how Apache HTTP Server came into existence and then install the most current stable version on CentOS Linux 7.

Brief History on Apache WebServer

Apache 是一个由来已久的 Web 服务器。事实上,几乎与 http 本身一样长!

Apache is a web server that has been around for a long time. In fact, almost as long as the existence of http itself!

Apache 最初是美国国家超级计算应用中心(也称为 NCSA)的一个相当小的项目。在 90 年代中期,“httpd”(当时称为这个名字)是互联网上最流行的 Web 服务器平台,拥有约 90% 或以上的市场份额。

Apache started out as a rather small project at the National Center for Supercomputing Applications also known as NCSA. In the mid-90’s "httpd", as it was called, was by far the most popular web-server platform on the Internet, having about 90% or more of the market share.

当时,这是一个简单的项目。被称为网站管理员的熟练 IT 人员负责:维护 Web 服务器平台和 Web 服务器软件以及前端和后端网站开发。httpd 的核心是其使用称为插件或扩展的自定义模块的能力。网站管理员足够熟练,可以编写核心服务器软件的补丁。

At this time, it was a simple project. Skilled I.T. staff known as webmaster were responsible for: maintaining web server platforms and web server software as well as both front-end and back-end site development. At the core of httpd was its ability to use custom modules known as plugins or extensions. A webmaster was also skilled enough to write patches to core server software.

在 90 年代中后期,httpd 的高级开发人员和项目经理离开 NCSA 去做别的事情。这使得最流行的 Web 守护进程处于停滞状态。

Sometime in the late-mid-90’s, the senior developer and project manager for httpd left NCSA to do other things. This left the most popular web-daemon in a state of stagnation.

由于 httpd 的使用如此广泛,一群经验丰富的 httpd 网站管理员要求召开峰会,商讨 httpd 的未来。他们决定协调并应用最佳扩展和补丁到当前的稳定版本中。然后,httpd 领域的鼻祖诞生了,并被命名为 Apache HTTP Server。

Since the use of httpd was so widespread a group of seasoned httpd webmasters called for a summit reqarding the future of httpd. It was decided to coordinate and apply the best extensions and patches into a current stable release. Then, the current grand-daddy of http servers was born and christened Apache HTTP Server.

Little Known Historical Fact - Apache 的名字不是来自美洲原住民部落的勇士。实际上,它的名字是这样创造和命名的:由许多才华横溢的计算机科学家提供的许多修复(或补丁)组合而成,即 patchyApache

Little Known Historical Fact − Apache was not named after a Native American Tribe of warriors. It was in fact coined and named with a twist: being made from many fixes (or patches) from many talented Computer Scientists: a patchy or Apache.

Install Current Stable Version on CentOS Linux 7

Step 1 - 通过 yum 安装 httpd。

Step 1 − Install httpd via yum.

yum -y install httpd

此时,Apache HTTP Server 将通过 yum 安装。

At this point Apache HTTP Server will install via yum.

Step 2 - 编辑针对您的 httpd 需求的 httpd.conf 文件。

Step 2 − Edit httpd.conf file specific to your httpd needs.

在默认的 Apache 安装中,Apache 的配置文件名为 httpd.conf,位于 /etc/httpd/ 中。因此,让我们在 vim 中打开它。

With a default Apache install, the configuration file for Apache is named httpd.conf and is located in /etc/httpd/. So, let’s open it in vim.

在 vim 中打开的 httpd.conf 的前几行 -

The first few lines of httpd.conf opened in vim −

#
# 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 请求。

We will make the following changes to allow our CentOS install to serve http requests from http port 80.

Listening host and port

# 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 地址的多个接口。

From here, we change Apache to listen on a certain port or IP Address. For example, if we want to run httpd services on an alternative port such as 8080. Or if we have our web-server configured with multiple interfaces with separate IP addresses.

Listen

防止 Apache 附加到每个 IP 地址上的每个侦听守护进程。这有助于停止仅指定 IPv6 或 IPv4 流量。甚至绑定到多宿主主上的所有网络接口。

Keeps Apache from attaching to every listening daemon onto every IP Address. This is useful to stop specifying only IPv6 or IPv4 traffic. Or even binding to all network interfaces on a multi-homed host.

#
# 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/ 将从文档根检索和提供索引文件。

The "document root" is the default directory where Apache will look for an index file to serve for requests upon visiting your sever: http://www.yoursite.com/ will retrieve and serve the index file from your document root.

#
# 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"

Step 3 - 启动并启用 httpd 服务。

Step 3 − Start and Enable the httpd Service.

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

Step 4 - 配置防火墙以允许访问端口 80 请求。

Step 4 − Configure firewall to allow access to port 80 requests.

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