Apache/zh-cn

Apache HTTP Server Apache HTTP 服务器是一个高效的可扩展的 web 服务器. 它是当前因特网上使用最为普遍的 web 服务器之一.

安装
如果你要使用 Apache event MPM 模式, 把下面的内容添加到 make.conf 里面:

如果你要使用 Apach worker MPM 模式, 把下面的内容添加到 make.conf 里面:

查看Apache的USE标志

然后我们安装Apache：

Global USE 支持
开启 global USE 标志可以给Apache多提供一些其他的软件包. 可能在安装时，如果Apache依赖其他软件时，他们就会被安装.

配置USE变量以后，更新系统来使得某些配置生效.

文件
在系统里，Apache2有两个主要的配置文件：


 * Gentoo 的 Apache2 初始化配置文件


 * Apache2 服务器的常规配置文件

位于 ，他是 Gentoo 初始化脚步配置的文件. 唯一生效的一行是 APACHE2_OPTS :

这个定义将解释使用 语句激活或停用整个配置的各种配置文件某些部分的选项. 下文将详细介绍.

The file is Apache server's conventional configuration file. In fact this file is only an entry point for configuration. The whole configuration is split in many files in the directory, that are assembled together using the   directive. For example, the statement, in , aims at including all the files in  which name ends with.

Taking into account what has been said in the subsection above, and as module configuration files (files in ) almost always start with the, the content of one file inside , will ONLY be assembled with the rest of the configuration, if the matching option is set using a   flag in the APACHE2_OPTS variable in the  file. The configuration file is an exception to this rule as it doesn't start with an   statement and therefore is always included in the resulting configuration.

默认值
After a fresh install of an Apache server, the configuration resulting from the assemblage of the different configuration files is as follows. Start with the entry point.

First sign of life
As visible in the initial configuration above, the pre-installed virtual host's   directory is, its server name is localhost. In addition an index.html file is provided in the  directory, thus to check whether everything is correctly installed or not, point a browser to http://localhost/.

"It works!"的字样应该被打印到您的屏幕上.

开启 mod_security
安装 :

要开启的 模块，更改 APACHE2_OPTS 的值:

要控制这些模块，请更改 和两个文件，然后重启Apache.

开启 PHP 支持
安装 PHP 附带  USE 标志，然后开启PHP模块:

在测试PHP模块是否工作前，检查文件 是否存在，是否包含以下默认值.

如果不存在请手动创建一个.

要验证PHP模块是否启动，创建个测试页面：

现在，把他重命名为 ，然后打开测试页面：

应该可以看到一个描述PHP配置的表格.

修改 PHP 版本
To change the version of PHP handled by Apache, first list the available versions for the  Server Application Programming Interface (SAPI):

改变选择：

Substitute  in the example above to the requested number in the output of  as displayed earlier on.

虚拟主机
For each virtual host, provide a  directory that is reachable and accessible by the Apache daemon. Add a virtual host configuration file in the  directory which uses this   and the virtual host server name. Do not forget to add an entry for this domain name in.

To assign the apache user/group ownership on the virtual host files, use like in the following example:

Below are two example virtual host definitions, one for domainname1.com and one for domainname2.com. Notice the different  and   directives even though the host itself  remains the same:

建议也提供基于IP的虚拟主机. 这允许管理员尝试为通过其IP地址访问网站的用户发送消息：

加入虚拟主机后，服务器需要（正常）重新启动以使新站点变为活动状态.

通过fcgid 开启 PHP
安装 和. PHP 这个包需要有  这个USE标志:

编辑 :

创建所需要的目录：

软链接到PHP wrapper：

开启 模块：

最后重启并检查. 应该被设置为 CGI/FastCGI.

在Apache 2.4上通过 mod_proxy_fcgi开启PHP-FPM
必须满足以下条件才能通过mod_proxy_fcgi启用PHP-FPM：
 * >= PHP 5.3
 * >= Apache 2.4

Furthermore, there are a few restrictions on the availability of functionality within Apache 2.4:
 * >= Apache 2.4.9, if you want to communicate with PHP-FPM over UNIX sockets
 * >= Apache 2.4.10, if you want to use SetHandler instead of ProxyPassMatch.

The following configuration will only work with Apache 2.4.10 and newer. It relies on the  directive and be placed within the main server config or. The location of the UNIX socket is determined by the  directive in the  configuration file, allowing for specifying separate pools per site or function.

在下面的例子中  被放在Apache的PHP模块配置文件中：

或者，您可以使用ProxyPassMatch - 这是唯一的选项，如果Apache版本在2.4.0和2.4.8之间.

默认情况下， 指令未设置为socket. 首先创建socket文件的目录：

接下来，像下面这样更新:

同时开启 和   模块:

OpenRC
开启Apache服务

将Apache添加至default runlevel：

重启Apache服务

重新读取Apache配置文件：

systemd
开启Apache服务

将Apache添加至default runlevel：

重启Apache服务

资源
Apache很难配置的很好. 下面是一些可能有用的资源，如果你遇到错误可以看看.


 * Troubleshooting guide

测试
验证Apache上一个IP端口是否开启并监听：

测试Apache服务器在localhost上是否正常工作：

可以使用+ 或者 来中断测试.

apr_sockaddr_info_get failed for 
错误:

apache2: apr_sockaddr_info_get failed for System_Hostname

Resolution:

When this occurs, add the host name to the file:

另请参阅

 * Lighttpd - 一个快速，轻量级的Web服务器.
 * Nginx - 一个轻量级，强大，高性能的HTTP服务器和反向代理工具.

外部资源

 * Slicehost article: Installing Apache on Gentoo
 * Slicehost article: Apache configuration files on Gentoo
 * Slicehost article: Configuring the Apache MPM on Gentoo
 * Slicehost article: Apache configuration on Gentoo
 * Slicehost article: Apache Virtual Hosts on Gentoo
 * Slicehost article: Enabling and using apache's mod_status on Gentoo
 * apache.org documentation
 * Apache2 mod_pagespeed