apache檢查httpd.conf的語法錯誤的方法


修改了apache httpd.conf文件之后,怎么樣驗證其語法是否正確呢?

當然,我們可以重新啟動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環境: 

apachectl configtest 
或 
apache2ctl configtest 
SuSE等系統的apache2,可能為apache2ctl命令。 

如果你不能確認自己的apache服務器到底使用哪個命令,你可以使用 

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

來查找一下。 

如果正確無誤,會顯示Syntax OK信息。 

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

如果存在錯誤,則會顯示出錯的行號以及錯誤信息,如下: 

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)

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM