如何解决常见的Apache错误

Common Apache Errors 常见的Apache错误

This tutorial series explains how to troubleshoot and fix some of the most common errors that you may encounter when using the Apache web server.

本教程系列说明了如何解决和修复使用Apache Web服务器时可能遇到的一些最常见的错误。

Each tutorial in this series includes descriptions of common Apache configuration, network, filesystem, or permission errors. The series begins with an overview of the commands and log files that you can use to troubleshoot Apache. Subsequent tutorials examine specific errors in detail.

本系列中的每个教程都包含对常见Apache配置,网络,文件系统或权限错误的描述。 本系列文章首先概述了可用于对Apache进行故障排除的命令和日志文件。 后续教程将详细检查特定的错误。

介绍 (Introduction)

There are three main commands, and a set of common log locations that you can use to get started troubleshooting Apache errors. Generally when you are troubleshooting Apache, you will use these commands in the order indicated here, and then examine log files for specific diagnostic data.

您可以使用三个主要命令和一组常用日志位置来开始对Apache错误进行故障排除。 通常,在对Apa​​che进行故障排除时,将按照此处指示的顺序使用这些命令,然后检查日志文件中的特定诊断数据。

The commands that you will commonly use to troubleshoot Apache across most Linux distributions are:

在大多数Linux发行版中,通常用于对Apache进行故障排除的命令是:

  • systemctl - Used to control and interact with Linux services via the systemd service manager.

    systemctl用于通过systemd服务管理器控制Linux服务并与之交互。

  • journalctl - Used to query and view the logs that are generated by systemd.

    journalctl用于查询和查看systemd生成的日志。

  • apachectl - When troubleshooting, this command is used to check Apache’s configuration.

    apachectl故障排除时,此命令用于检查Apache的配置。

These commands, how to use them, and Apache’s log locations where you can find additional information about errors are described in further detail in the following sections.

这些命令,如何使用它们以及可以在其中找到有关错误的其他信息的Apache日志位置将在以下各节中详细描述。

Note: On Debian and Ubuntu systems, the Apache service and process name is apache2, whereas on CentOS, Fedora, and other RedHat-derived systems, Apache’s service and process name is httpd. Apart from the differences between the service and running process names, starting, stopping, and checking Apache’s status, as well as logs with journalctl should work the same on any Linux system that uses systemd to manage the Apache service. Be sure to use the correct name for your Linux distribution.

注意 :在Debian和Ubuntu系统上,Apache服务和进程名称是apache2 ,而在CentOS,Fedora和其他RedHat派生的系统上,Apache的服务和进程名称是httpd 。 除了服务和运行进程名称之间的差异之外,启动,停止和检查Apache状态以及带有journalctl日志在任何使用systemd管理Apache服务的Linux系统上均应相同。 确保为您的Linux发行版使用正确的名称。

适用于Apache的systemctl命令 (systemctl Commands for Apache)

To troubleshoot common Apache errors using the systemd service manager, the first step is to inspect the state of the Apache processes on your system. The following systemctl commands will query systemd for the state of Apache’s processes.

要使用systemd服务管理器解决常见的Apache错误,第一步是检查系统上Apache进程的状态。 以下systemctl命令将查询systemd以获取Apache进程的状态。

On Ubuntu and Debian systems run:

在Ubuntu和Debian系统上运行:

  • sudo systemctl status apache2.service -l --no-pager

    sudo systemctl状态apache2.service -l --no-pager

The -l flag will ensure that output is not truncated or ellipsized. The --no-pager flag will make sure that output will go directly to your terminal without requiring any interaction on your part to view it. You should receive output like this:

-l标志将确保输出不会被截断或省略。 --no-pager标志将确保输出直接进入终端,而无需您进行任何交互来查看它。 您应该收到如下输出:


   
     
     
     
     
Output
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: active (running) since Mon 2020-07-13 14:43:35 UTC; 1 day 4h ago Process: 929 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) Main PID: 1346 (apache2) Tasks: 55 (limit: 4702) CGroup: /system.slice/apache2.service ├─1346 /usr/sbin/apache2 -k start . . .

To inspect the Apache process on CentOS and Fedora systems run:

要在CentOS和Fedora系统上检查Apache进程,请运行:

  • sudo systemctl status httpd.service -l --no-pager

    sudo systemctl状态httpd.service -l --no-pager

You should receive output like this:

您应该收到如下输出:


   
     
     
     
     
Output
● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2020-07-14 19:46:52 UTC; 3s ago Docs: man:httpd.service(8) Main PID: 21217 (httpd) Status: "Started, listening on: port 80" Tasks: 213 (limit: 2881) Memory: 16.6M CGroup: /system.slice/httpd.service ├─21217 /usr/sbin/httpd -DFOREGROUND . . . Jul 14 19:46:52 localhost.localdomain httpd[21217]: Server configured, listening on: port 80

In either case, make a note of the Active line in the output. If your Apache server does not show active (running) as highlighted in the previous examples but you expect it should, there may be an error. Typically if there is a problem, you will have a line like the following in your output (note the highlighted failed portion):

无论哪种情况,都请记下输出中的Active行。 如果您的Apache服务器未如前面示例中所示突出显示active (running) ,但您希望这样做,则可能存在错误。 通常,如果出现问题,输出中将出现类似于以下内容的行(请注意突出显示的failed部分):


   
     
     
     
     
Example Error Output
Active: failed (Result: exit-code) since Tue 2020-07-14 20:01:29 UTC; 1s ago

If there is a problem with your Apache process or configuration you can troubleshoot it further using the journalctl command.

如果您的Apache进程或配置存在问题,则可以使用journalctl命令对其进行进一步的故障排除。

journalctl于Apache的journalctl命令 (journalctl Commands for Apache)

To inspect the systemd logs for Apache, you can use the journalctl command. The systemd logs for Apache will usually indicate whether there is a problem with starting or managing the Apache process.

要检查Apache的systemd日志,可以使用journalctl命令。 Apache的systemd日志通常会指示启动或管理Apache进程是否存在问题。

These logs are separate from Apache’s request and error logs. journalctl displays logs from systemd that describe the Apache service itself, from startup to shutdown, along with any process errors that may be encountered along the way.

这些日志与Apache的请求和错误日志分开。 journalctl显示来自systemd日志,这些日志描述了从启动到关闭的Apache服务本身,以及在此过程中可能遇到的任何过程错误。

On Ubuntu and Debian systems use the following command to examine the logs:

在Ubuntu和Debian系统上,使用以下命令检查日志:

  • sudo journalctl -u apache2.service --since today --no-pager

    sudo journalctl -u apache2.service-从今天开始--no-pager

The --since today flag will limit the output of the command to log entries beginning at 00:00:00 of the current day only. Using this option will help restrict the volume of log entries that you need to examine when checking for errors. You should receive output like the following:

--since today标志将限制命令的输出,仅记录从当天的00:00:00开始的条目。 使用此选项将有助于限制检查错误时需要检查的日志条目的数量。 您应该收到如下输出:


   
     
     
     
     
Output
Jul 14 20:12:14 ubuntu2004 systemd[1]: Starting The Apache HTTP Server... Jul 14 20:12:14 ubuntu2004 systemd[1]: Started The Apache HTTP Server.

If you are using a CentOS or Fedora based system, use this version of the command:

如果您使用的是基于CentOS或Fedora的系统,请使用以下版本的命令:

  • sudo journalctl -u httpd.service --since today --no-pager

    sudo journalctl -u httpd.service-从今天开始--no-pager

You should receive output like the following:

您应该收到如下输出:


   
     
     
     
     
Output
Jul 14 20:13:09 centos8 systemd[1]: Starting The Apache HTTP Server... . . . Jul 14 20:13:10 centos8 httpd[21591]: Server configured, listening on: port 80

If there is an error, you will have a line in the output that is similar to the following, with the main difference between Linux distributions being the highlighted yourhostname portion:

如果有错误,输出中将与以下内容相似,Linux发行版之间的主要区别是突出显示的yourhostname部分:


   
     
     
     
     
Example Error Output
Jul 14 20:13:37 yourhostname systemd[1]: Failed to start The Apache HTTP Server.

If your Apache server has errors in the journalctl logs like the previous example, then the next step to troubleshoot possible issues is investigating Apache’s configuration using the apachectl command line tool.

如果您的Apache服务器像前面的示例一样在journalctl日志中有错误,则解决可能出现的问题的下一步是使用apachectl命令行工具调查Apache的配置。

使用apachectl故障排除 (Troubleshooting with apachectl)

Most Linux distributions include the apachectl utility with Apache. apachectl is an invaluable tool to help detect and diagnose Apache configuration problems.

大多数Linux发行版都包含Apache的apachectl实用程序。 apachectl是帮助检测和诊断Apache配置问题的宝贵工具。

To troubleshoot issues using apachectl, test your Apache configuration using the apachectl configtest command. The tool will parse your Apache files and detect any errors or missing settings before attempting to start the server.

要使用apachectl解决问题,请使用apachectl configtest命令测试您的Apache配置。 该工具将解析您的Apache文件,并在尝试启动服务器之前检测任何错误或缺少设置。

Run the command like this on Ubuntu, Debian, CentOS, and Fedora based distributions:

在基于Ubuntu,Debian,CentOS和Fedora的发行版上运行以下命令:

  • sudo apachectl configtest

    须藤apachectl configtest

A working Apache configuration will result in output like the following:

有效的Apache配置将导致如下输出:


   
     
     
     
     
Output
Syntax OK

Depending on your Linux distribution, there may be other lines mixed in with the output, but the important line is the one that says Syntax OK.

根据您的Linux发行版,输出中可能还会混入其他行,但是重要的一行是说Syntax OK那一Syntax OK

If there is an error in your Apache configuration, like a directive that references a module that is not enabled or even a single typo, apachectl will detect it and attempt to notify you about the problem.

如果您的Apache配置中存在错误,例如引用未启用的模块或什至是单个错字的指令,则apachectl将检测到该错误并尝试将问题通知您。

For example, attempting to use directives for an Apache module that is not enabled will result in apachectl configtest messages like the following:

例如,尝试对未启用的Apache模块使用指令将导致apachectl configtest消息,如下所示:


   
     
     
     
     
Example Error Output
AH00526: Syntax error on line 232 of /etc/apache2/apache2.conf: Invalid command 'SSLEngine', perhaps misspelled or defined by a module not included in the server configuration Action 'configtest' failed. The Apache error log may have more information.

In this example the ssl module is not enabled, so the SSLEngine directive generates an error when the configuration is tested. The last line also indicates that The Apache error log may have more information, which is the next place to look for more detailed debugging information.

在此示例中,未启用ssl模块,因此SSLEngine指令在测试配置时会生成错误。 最后一行还表明The Apache error log may have more information ,这是查找更详细的调试信息的下一个地方。

Apache日志文件 (Apache Log Files)

Apache log files are a very helpful resource for troubleshooting. Generally, any error that you receive in a browser or other HTTP client will have a corresponding entry in Apache’s logs. Sometimes Apache will also output errors related to configuration, built-in modules, and other debugging information to its log files.

Apache日志文件是用于故障排除的非常有用的资源。 通常,您在浏览器或其他HTTP客户端中收到的任何错误都会在Apache的日志中具有相应的条目。 有时,Apache还将与配置,内置模块和其他调试信息有关的错误输出到其日志文件。

To examine log files for errors while troubleshooting Apache on a Fedora, CentOS, or RedHat server, examine the /var/log/httpd/error_log file.

要在Fedora,CentOS或RedHat服务器上对Apache进行故障排除时检查日志文件中的错误,请检查/var/log/httpd/error_log文件。

If you are troubleshooting a Debian or Ubuntu derived system, examine /var/log/apache2/error.log for errors using a tool like tail or less. For example, to view the last two lines of the error log using tail, run the following command:

如果要对Debian或Ubuntu派生的系统进行故障排除,请使用tailless类的工具检查/var/log/apache2/error.log中的错误。 例如,要使用tail查看错误日志的最后两行,请运行以下命令:

  • sudo tail -n 2 /var/log/apache2/error.log

    须藤尾-n 2 /var/log/apache2/error.log

Substitute the number of lines that you would like to examine in place of the number 2 in the command. On a CentOS or Fedora system, the log file to examine is /var/log/httpd/error_log.

用您想要检查的行数代替命令中的数字2 。 在CentOS或Fedora系统上,要检查的日志文件是/var/log/httpd/error_log

An example error will resemble something like the following lines, regardless of which Linux distribution you are using to run your Apache server:

无论您使用哪个Linux发行版来运行Apache服务器,示例错误都类似于以下几行:


   
     
     
     
     
Error Log Examples
[Wed Jul 15 01:34:12.093005 2020] [proxy:error] [pid 13949:tid 140150453516032] (13)Permission denied: AH00957: HTTP: attempt to connect to 127.0.0.1:9090 (127.0.0.1) failed [Wed Jul 15 01:34:12.093078 2020] [proxy_http:error] [pid 13949:tid 140150453516032] [client 127.0.0.1:42480] AH01114: HTTP: failed to make connection to backend: 127.0.0.1

The two lines in this output are distinct error messages. They both reference the module causing the error (proxy in the first line, proxy_http in the second) and include an error code that is specific to the module. The first one, AH00957, indicates that the Apache server attempted to connect to a backend server (127.0.0.1 on port 9090 in this case) using the proxy module but failed to do so.

此输出中的两行是不同的错误消息。 它们都引用导致错误的模块(第一行中的proxy ,第二行中的proxy_http ),并包含特定于模块的错误代码。 第一个是AH00957 ,它指示Apache服务器尝试使用proxy模块连接到后端服务器(在本例中为端口9090上的127.0.0.1),但没有成功。

The second error is derived from the first: AH01114 is a proxy_http module error that also indicates that Apache was unable to connect to the configured backend server to make an HTTP request.

第二个错误是从第一个错误派生的:AH01114是proxy_http模块错误,它还指示Apache无法连接到配置的后端服务器以发出HTTP请求。

These example lines are just for illustration purposes. If you are diagnosing errors with your Apache server, chances are the error lines in your logs will have different contents than these. Regardless of your Linux distribution, the format of any error lines in your logs will include the relevant Apache module and error code, as well as a text description of the error.

这些示例行仅用于说明目的。 如果您正在使用Apache服务器诊断错误,则日志中的错误行的内容可能会与此不同。 无论您使用的是Linux发行版,日志中任何错误行的格式都将包含相关的Apache模块和错误代码,以及错误的文本描述。

Once you have an idea of what might be causing problems with your Apache server you can continue researching and troubleshooting the issue. The error code and text description are especially useful, since they give you explicit and specific terms that you can use to narrow down the range of possible causes of a problem.

一旦了解了可能导致Apache服务器出现问题的原因,就可以继续研究问题并对其进行故障排除。 错误代码和文本描述特别有用,因为它们为您提供了明确的术语和特定的术语,您可以使用它们来缩小问题的可能原因范围。

结论 (Conclusion)

Troubleshooting Apache errors can range from diagnosing errors with the service itself, to locating misconfigured options for modules, or to examining customized access control rules in detail. This introduction to diagnosing issues with Apache explained how to use a number of utilities to help narrow down the possible causes of errors. Usually, you will use these utilities in the same order, although you can always skip some, or start directly with examining logs if you have a general idea of what the problem might be.

对Apache错误进行故障排除的范围包括诊断服务本身的错误,查找模块配置错误的选项或详细检查自定义的访问控制规则。 本诊断Apache问题的简介介绍了如何使用许多实用程序来帮助缩小错误的可能原因。 通常,您将以相同的顺序使用这些实用程序,尽管您始终可以跳过某些实用程序,或者如果您对可能的问题有一个大致的了解,则可以直接从检查日志开始。

However, as a general sequence for troubleshooting, it helps to be methodical and use these tools in the order described. Start troubleshooting with systemctl to examine the state of the Apache server. If you need more information, examine the systemd logs for Apache using the journalctl command. If the issue is still not apparent after checking journalctl, testing Apache’s configuration using apachectl configtest is the next step. Finally, for in-depth troubleshooting, examining Apache’s log files will usually indicate a specific error, with helpful diagnostic messages and error codes.

但是,作为进行故障排除的一般顺序,它有助于系统地进行操作并按所述顺序使用这些工具。 使用systemctl开始进行故障排除,以检查Apache服务器的状态。 如果需要更多信息,请使用journalctl命令检查Apache的systemd日志。 如果在检查journalctl之后问题仍然journalctl ,则下一步是使用apachectl configtest测试Apache的配置。 最后,为进行深入的故障排除,检查Apache的日志文件通常会指示特定的错误,以及有用的诊断消息和错误代码。

The rest of the tutorials in this series will examine some common errors that you may encounter when using Apache in more detail.

本系列的其余教程将详细研究使用Apache时可能遇到的一些常见错误。

翻译自: https://www.digitalocean.com/community/tutorials/how-to-troubleshoot-common-apache-errors

你可能感兴趣的:(linux,java,python,运维,分布式)