Apache httpd.conf 配置文件语法验证

Apache httpd.conf 配置文件语法验证

admin
2017-11-08 / 0 评论 / 1,268 阅读 / 正在检测是否收录...

Apache 的 httpd.conf文件修改之后,必须重启服务器才能生效。有时服务器在提供服务的时候,直接更改配置,重启服务,会带来很大的危险性。

比如下面这样的错误日志

11:22:48  [Apache]     Error: Apache shutdown unexpectedly.
11:22:48  [Apache]     This may be due to a blocked port, missing dependencies, 
11:22:48  [Apache]     improper privileges, a crash, or a shutdown by another method.
11:22:48  [Apache]     Press the Logs button to view error logs and check
11:22:48  [Apache]     the Windows Event Viewer for more clues
11:22:48  [Apache]     If you need more help, copy and post this
11:22:48  [Apache]     entire log window on the forums

咋一看 以为是端口被占用,遇到这样的问题,我们先查看端口占用情况

1,开始—->运行—->cmd,或者是window+R组合键,调出命令窗口,

2,输入命令:netstat -ano,列出所有端口的情况。在列表中我们观察“本地地址”那一列被占用的端口

如果通过以上方法发现我们的端口没有被占用,那多半是我们的Apache配置文件出错了,那么我们需要一种方法,可以检测我们的Apache配置文件有没有语法错误。如果能在修改配置之后,先验证语法正确与否,再重启服务器,则能避免一些不必要的错误。

对以上需求,Apache本身提供了相应的命令来验证配置文件的语法。

Windows环境的命令:

httpd -t (注:如果您的电脑没有未Apache配置环境变量,需要进入到Apache目录的bin目录下执行该命令)

Linux环境的命令:

[root@server bin]# ./apachectl configtest

如果正确无误,会显示Syntax OK信息

Syntax OK

如果存在错误,则会显示出错的行号以及错误信息,如下:

AH00526: Syntax error on line 639 of D:/xampp/apache/conf/httpd.conf:
<Directory> directive missing closing '>'

AH00526: Syntax error on line 639 of D:/xampp/apache/conf/httpd.conf:
<Directory> directive missing closing '>'
0

评论 (0)

取消