2011-03-29 27 views
101

再一次,我的apache虛擬主機配置有問題。 (使用默認配置而不是我的特定配置)。如何調試apache虛擬主機配置?

問題並非真正的錯誤配置,而是如何解決它。

有沒有人有很好的建議來解決這類問題很快?

更多信息。

默認的conf文件是這個:不適用

NameVirtualHost * 
<VirtualHost *> 
     ServerAdmin [email protected] 

     DocumentRoot /var/www/ 
     <Directory /> 
       Options FollowSymLinks 
       AllowOverride None 
     </Directory> 
     <Directory /var/www/> 
       Options Indexes FollowSymLinks MultiViews 
       AllowOverride None 
       Order allow,deny 
       allow from all 
     </Directory> 

     ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
     <Directory "/usr/lib/cgi-bin"> 
       AllowOverride None 
       Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
       Order allow,deny 
       Allow from all 
     </Directory> 

     ErrorLog /var/log/apache2/error.log 

     # Possible values include: debug, info, notice, warn, error, crit, 
     # alert, emerg. 
     LogLevel warn 

     CustomLog /var/log/apache2/access.log combined 
     ServerSignature On 

    Alias /doc/ "/usr/share/doc/" 
    <Directory "/usr/share/doc/"> 
     Options Indexes MultiViews FollowSymLinks 
     AllowOverride None 
     Order deny,allow 
     Deny from all 
     Allow from 127.0.0.0/255.0.0.0 ::1/128 
    </Directory> 

</VirtualHost> 

以及虛擬主機的配置是這樣的一個:

<VirtualHost *:*> 

ProxyPreserveHost On 
ProxyPass/http://ip.ip.ip.ip:8088/ 
ProxyPassReverse/http://ip.ip.ip.ip:8088/ 
ServerName wiki.mydomain.com 

</VirtualHost> 
+2

你想告訴我們問題是什麼?向我們展示您的conf文件也許會有幫助。 – davidstites 2011-03-29 14:50:11

+1

你在使用什麼操作系統? – EmCo 2011-03-29 14:51:28

+0

ubuntu 8.04 LTS – GaetanZ 2011-03-31 21:36:31

回答

141

語法檢查

要檢查配置文件的語法錯誤:

# Fedora, RHEL, CentOS, OSX 
httpd -t 

# Debian, Ubuntu 
apache2ctl -t 

# MacOS 
apachectl -t 

名單虛擬主機

要列出所有虛擬主機,和它們的位置:

# Fedora, RHEL, CentOS, OSX 
httpd -S 

# Debian, Ubuntu 
apache2ctl -S 

# MacOS 
apachectl -S 
+3

'-S'是'-t -D DUMP_VHOSTS'的同義詞,所以這兩個是相同的 – 2015-01-20 19:40:56

+0

我已經更新了答案。謝謝! – sqren 2015-01-20 22:19:23

+0

可能要遲到了,但我會喜歡一些windows命令... – GiantCowFilms 2015-11-11 16:44:56

10

首先檢查出config文件的語法錯誤與apachectl configtest然後看看Apache的錯誤logs

+0

我沒有語法錯誤,因爲我的服務器重新啓動並重新加載配置沒有任何問題。我不知道在哪個日誌中可以找到有關我的配置的詳細信息。 – GaetanZ 2011-03-31 14:35:09

+0

錯誤日誌通常位於'/var/log/apache2/error.log'文件中。 – yojimbo87 2011-03-31 14:39:04

+1

對於apache2,命令應該是:「apache2ctl configtest」 – eaykin 2012-09-10 14:21:15

20

如果您正嘗試調試您的虛擬主機配置,您可能會發現Apache -S com任務線開關很有用。也就是說,鍵入以下命令:

httpd -S 

此命令將轉儲出有關Apache如何分析配置文件的說明。仔細檢查IP地址和服務器名稱可能有助於發現配置錯誤。 (有關其他命令行選項,請參閱httpd程序的文檔)。

+9

在Apache2的,這是'apache2ctl -S' – artfulrobot 2013-07-05 15:06:03

+1

或交替'APACHE_RUN_USER = WWW的數據APACHE_RUN_GROUP = WWW- data/usr/sbin/apache2 -S' – rleir 2013-08-19 19:56:40

20

這裏有一個命令,我認爲可能會有所幫助:

apachectl -t -D DUMP_VHOSTS 

你會得到所有的虛擬主機的名單,你就會知道哪一個是默認的,你會確保你的語法是正確的(和yojimbo87建議的apachectl configtest相同)。

您還會知道每個虛擬主機在哪裏聲明。如果你的配置文件亂七八糟,它可以很方便。 ;)

4

我最近有一些VirtualHost的問題。我用a2ensite移動能使一臺主機,但運行正常重啓(這將殺死失敗服務器)之前,我跑

apache2ctl -S 

,讓你瞭解正在發生的事情與你的虛擬主機的一些信息。這並不完美,但它有幫助。

7

我有一個新的VirtualHost配置文件,在使用apachectl -S命令時沒有顯示。在經歷了許多搔頭之後,我意識到我的文件沒有後綴「.conf」。一旦我用該後綴重命名文件,我的Vhost就開始顯示並運行了!

1

我發現我自己的錯,我沒有添加日誌文件名: 錯誤日誌在/ var /日誌/ Apache2的
而這個路徑: 目錄「的/ usr /共享/ DOC /」 不包含網站源。

當我改變了這兩個,所有的工作。 有趣的是,apache沒有發出任何錯誤,只是沒有在我的Mac OS Sierra上靜靜地打開我的網站。