apache检查httpd.conf的语法错误的方法

修改了apache httpd.conf文件以后,怎么样验证其语法是否正确呢?apache

固然,咱们能够从新启动apache服务器,但这样一来,若是万一存在错误,apache服务器将不能正常启动,也不能提供正常服务。服务器

因此咱们在修改了apache的配置文件以后,最好对其验证,确保了其语法上正确无误以后,才从新启动apache服务器。 
 
apache httpd.conf语法验证能够经过下面的命令来验证。 
Windows环境: 
httpd -t 
或者: 
httpd.exe -w -t -f "C:\Apache2.2\conf\httpd.conf" -d "C:\Apache2.2\." 

 

Linux环境: spa

apachectl configtest 
或 
apache2ctl configtest 
SuSE等系统的apache2,可能为apache2ctl命令。 

若是你不能确认本身的apache服务器到底使用哪一个命令,你能够使用 code

find / -name "apachectl" 
或者 
find / -name "apache2ctl" 

来查找一下。 orm

若是正确无误,会显示Syntax OK信息。 blog

sudo /Applications/MAMP/Library/bin/apachectl  configtest
Syntax OK

若是存在错误,则会显示出错的行号以及错误信息,以下: three

sudo /Applications/MAMP/Library/bin/apachectl  configtest
Syntax error on line 623 of /Applications/MAMP/conf/apache/httpd.conf: CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional "env=" clause (see docs)
相关文章
相关标签/搜索