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进行故障排除的命令和日志文件。 后续教程将详细检查特定的错误。
An Apache AH00526: Syntax error
message occurs when there is a typo or misconfigured setting somewhere in your Apache configuration files. It is a generic error that can be indicative of a number of underlying problems.
当Apache配置文件中的某个地方出现错字或配置错误时,就会出现Apache AH00526: Syntax error
消息。 这是一个一般性错误,可以指示许多潜在问题。
The error can be detected using apachectl configtest
before an invalid configuration is loaded. It can also be found using the systemctl
and journalctl
commands. In the latter two cases, Apache will be unable to run because of the error.
在加载无效的配置之前,可以使用apachectl configtest
检测到该错误。 也可以使用systemctl
和journalctl
命令找到它。 在后两种情况下,Apache将由于该错误而无法运行。
If you have detected the error using apachectl
then skip to the Troubleshooting Using the Built in apachectl
Command section of this tutorial. Otherwise, the next section will explain how to use systemctl
to troubleshoot the error.
如果使用apachectl
检测到错误,请跳至本教程的“ 使用内置apachectl
命令进行故障排除”部分。 否则,下一节将说明如何使用systemctl
对错误进行故障排除。
systemctl
故障排除 (Troubleshooting with systemctl
)Following the troubleshooting steps from the How to Troubleshoot Common Apache Errors tutorial at the beginning of this series, the first step when you are troubleshooting an AH00526 error is to check Apache’s status with systemctl
. It is important to understand if the error affects the running process, or if it is preventing Apache from starting up.
按照本系列文章开头的“ 如何对常见的Apache错误进行故障排除”教程中的故障排除步骤进行操作之后,对AH00526错误进行故障排除的第一步是使用systemctl
检查Apache的状态。 重要的是要了解该错误是否影响正在运行的进程,或者是否正在阻止Apache启动。
On Ubuntu and Debian derived Linux distributions, run the following to check Apache’s status:
在Ubuntu和Debian派生的Linux发行版上,运行以下命令检查Apache的状态:
On CentOS and Fedora systems, use this command to examine Apache’s status:
在CentOS和Fedora系统上,使用以下命令检查Apache的状态:
The -l
flag will ensure that systemctl
outputs the entire contents of a line, instead of substituting in ellipses (…
) for long lines. The --no-pager
flag will output the entire log to your screen without invoking a tool like less
that only shows a screen of content at a time.
-l
标志将确保systemctl
输出一行的全部内容,而不是用省略号( …
)代替长行。 --no-pager
标志将整个日志输出到您的屏幕,而无需调用诸如less
的工具,该工具一次只显示一个屏幕。
Since you are troubleshooting an AH00526: Syntax error
message, you should receive output that is similar to the following:
由于要对AH00526: Syntax error
消息进行故障排除,因此您应该收到与以下内容相似的输出:
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: failed (Result: exit-code) since Wed 2020-07-15 13:45:49 UTC; 1min 37s ago
. . .
Jul 15 13:45:49 f17f01056c5b systemd[1]: Starting The Apache HTTP Server...
Jul 15 13:45:49 f17f01056c5b apachectl[15860]: AH00526: Syntax error on line 2 of /etc/apache2/sites-enabled/000-default.conf:
Jul 15 13:45:49 f17f01056c5b apachectl[15860]: Invalid command 'SSSLCertificateFile', perhaps misspelled or defined by a module not included in the server configuration
Jul 15 13:45:49 f17f01056c5b apachectl[15860]: Action 'start' failed.
Jul 15 13:45:49 f17f01056c5b apachectl[15860]: The Apache error log may have more information.
Jul 15 13:45:49 f17f01056c5b systemd[1]: apache2.service: Control process exited, code=exited status=1
Jul 15 13:45:49 f17f01056c5b systemd[1]: apache2.service: Failed with result 'exit-code'.
Jul 15 13:45:49 f17f01056c5b systemd[1]: Failed to start The Apache HTTP Server.
In this case, Apache is not running because of the syntax error. The error is caused by an extra S character at the beginning of the SSSLCertificateFile
line in the /etc/apache2/sites-enabled/000-default.conf
file. The correct directive should be SSLCertificateFile
, so editing the file to fix the directive name in this example would resolve the error and allow Apache to start.
在这种情况下,由于语法错误,Apache无法运行。 该错误是由/etc/apache2/sites-enabled/000-default.conf
文件中SSSLCertificateFile
行开头的额外S字符引起的。 正确的伪指令应该是SSLCertificateFile
,因此在此示例中编辑文件以修复伪指令名称将解决该错误并允许Apache启动。
The systemctl
output in this example also includes some lines from the systemd
journal. If your output indicates a specific line in your configuration file is generating the syntax error, you can skip the journalctl
and apachectl configtest
troubleshooting steps. Instead, you can go directly to the file to inspect and edit the erroneous line to resolve the error.
此示例中的systemctl
输出还包括来自systemd
日志的一些行。 如果输出表明配置文件中的特定行正在生成语法错误,则可以跳过journalctl
和apachectl configtest
故障排除步骤。 相反,您可以直接转到文件以检查和编辑错误行以解决错误。
If your output does not give specific information about the error location in Apache’s configuration files, you will need to examine journalctl
output from the systemd
logs. The following section explains how to use journalctl
to troubleshoot an AH00526 error.
如果您的输出未提供有关Apache配置文件中错误位置的特定信息,则需要检查systemd
日志中的journalctl
输出。 下节说明如何使用journalctl
对AH00526错误进行故障排除。
journalctl
日志进行故障排除 (Troubleshooting with journalctl
logs)If your systemctl
output does not include specifics about an AH00526 syntax error, you can proceed with using the journalctl
command to examine systemd
logs for Apache.
如果您的systemctl
输出不包含有关AH00526语法错误的详细信息,则可以继续使用journalctl
命令检查Apache的systemd
日志。
On Ubuntu and Debian-derived systems, run the following command:
在Ubuntu和Debian衍生的系统上,运行以下命令:
On CentOS, Fedora, and RedHat-derived systems, use this command to inspect the logs:
在CentOS,Fedora和RedHat派生的系统上,使用以下命令检查日志:
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.
--since today
标志将限制命令的输出,仅记录从当天的00:00:00开始的条目。 使用此选项将有助于限制检查错误时需要检查的日志条目的数量。
If you have an AH00526 error in your Apache configuration, look through the journalctl
command output for lines like the following:
如果您的Apache配置中出现AH00526错误,请在journalctl
命令输出中查找类似以下内容的行:
Output
-- Logs begin at Tue 2019-11-05 21:26:44 UTC, end at Tue 2020-06-09 15:13:01 UTC. --
. . .
Jun 09 15:12:28 f17f01056c5b apachectl[3157]: AH00526: Syntax error on line 3 of /etc/apache2/sites-enabled/000-default.conf:
Jun 09 15:12:28 f17f01056c5b apachectl[3157]: Invalid command 'SSLCertificateFile', perhaps misspelled or defined by a module not included in the server configuration
. . .
The first line of output is the AH00526 error. Since this error is a general error related to an invalid setting or a typo in a configuration file, the next line explains what caused the error. In this case it is a directive called SSLCertificateFile
, which will only be valid if the ssl
module is enabled.
输出的第一行是AH00526错误。 由于此错误是与无效的设置或配置文件中的错字有关的一般错误,因此下一行说明了引起该错误的原因。 在这种情况下,它是一个名为SSLCertificateFile
的指令,仅在启用ssl
模块时才有效。
If you encounter an AH00526 error that is related to an invalid SSLCertificateFile
directive, you can resolve it by enabling the ssl
module and then restarting Apache to make the error go away.
如果遇到与无效的SSLCertificateFile
指令相关的AH00526错误,则可以通过启用ssl
模块然后重新启动Apache来使错误消失,从而解决该错误。
For Ubuntu and Debian systems, run the following to enable the module:
对于Ubuntu和Debian系统,运行以下命令启用该模块:
On CentOS and Fedora systems, ensure that the mod_ssl
package is installed, and then load the module by adding it to Apache’s /etc/httpd/conf.modules.d
directory in a file like this:
在CentOS和Fedora系统上,确保已安装mod_ssl
软件包,然后通过将其添加到Apache的/etc/httpd/conf.modules.d
目录中的如下文件中来加载该模块:
Once the module is referenced by Apache and you restart it using the command that is appropriate to your Linux distribution, the server will start up if there are no more errors in the configuration.
Apache引用了该模块并使用适合您Linux发行版的命令重新启动该模块后,如果配置中没有更多错误,服务器将启动。
However, if there are more errors, Apache and systemctl status
will continue to report them and attempt to explain why the server cannot be started. systemctl
will output failure messages like this on Ubuntu and Debian systems:
但是,如果还有更多错误,Apache和systemctl status
将继续报告它们,并尝试解释为什么无法启动服务器。 systemctl
将在Ubuntu和Debian系统上输出如下失败消息:
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details
And on CentOS, Fedora, and RedHat derived systems, a failed startup message will be similar to the following:
在CentOS,Fedora和RedHat派生的系统上,失败的启动消息将类似于以下内容:
Job for httpd.service failed because the control process exited with error code.
See "systemctl status httpd.service" and "journalctl -xe" for details.
When Apache will still not start because of errors, using the apachectl configtest
command can be the most efficient and effective way to diagnose issues. The next section will explain how to use the utility to resolve an AH00526 error that is again related to an invalid SSLCertificateFile
directive.
当Apache由于错误仍无法启动时,使用apachectl configtest
命令可能是诊断问题的最有效方法。 下一节将说明如何使用该实用工具解决AH00526错误,该错误再次与无效的SSLCertificateFile
指令相关。
apachectl
故障排除 (Troubleshooting with apachectl
)To troubleshoot an AH00526 error with Apache’s apachectl
utility, you can test your Apache configuration using the configtest
sub-command. This tool will parse your Apache files to determine whether it’s valid and, if not, locate incorrect settings in the Apache configuration.
要使用Apache的apachectl
实用程序解决AH00526错误,可以使用configtest
子命令测试Apache配置。 该工具将解析您的Apache文件,以确定其是否有效,如果无效,则在Apache配置中找到错误的设置。
The apachectl configtest
command is useful for catching syntax errors before reloading apache with a new configuration. This test can help you to avoid service outages in the event of a misconfigured setting in your Apache files.
apachectl configtest
命令对于在使用新配置重新加载apache之前捕获语法错误很有用。 如果Apache文件中的配置错误,此测试可以帮助您避免服务中断。
The following example configuration test command will return an AH00526 Syntax error
message, and explains that the likely problem is that Apache is referencing an empty SSLCertificateFile
:
以下示例配置测试命令将返回AH00526 Syntax error
消息,并说明可能的问题是Apache引用了一个空的SSLCertificateFile
:
Output
AH00526: Syntax error on line 3 of /etc/apache2/sites-enabled/000-default.conf:
SSLCertificateFile: file '/etc/ssl/certs/example.com.pem' does not exist or is empty
In this example output, the /etc/ssl/certs/example.com.pem
file does not exist as the error message notes. Adding an SSL/TLS certificate to the file, or removing the directive will resolve the issue.
在此示例输出中,错误消息指出/etc/ssl/certs/example.com.pem
文件不存在。 在文件中添加SSL / TLS证书或删除指令将解决此问题。
A successful apachectl configtest
invocation should result in output like this:
成功的apachectl configtest
调用应导致如下输出:
Output
Syntax OK
In this tutorial you learned how to troubleshoot an Apache AH00526 syntax error. The first step when investigating any Apache error is to examine the server’s status with systemctl status apache2
, or systemctl status httpd
depending on your Linux distribution. From there, you can determine whether Apache is running correctly, or if it is unable to start because of the error.
在本教程中,您学习了如何解决Apache AH00526语法错误。 研究任何Apache错误的第一步是根据您的Linux发行版,使用systemctl status apache2
或systemctl status httpd
检查服务器状态。 从那里,您可以确定Apache是否运行正常,或者是否由于该错误而无法启动。
After you have determined Apache’s status, you can diagnose it further using journalctl
to examine the systemd
logs for the process. You can also use the apachectl configtest
command to check the configuration files for errors directly.
确定Apache的状态后,可以使用journalctl
进一步检查该进程的systemd
日志,以journalctl
进行诊断。 您也可以使用apachectl configtest
命令直接检查配置文件中是否有错误。
翻译自: https://www.digitalocean.com/community/tutorials/apache-configuration-error-ah00526-syntax-error
apache 配置错误信息