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)
相關文章
相關標籤/搜索