apache Internal Server Error 解決方法

今天配置nagios的時候遇到了一些麻煩.前面的步驟都一切順利,可是修改好全部的cfg後,點擊左邊的菜單時老是提示Internal Server Error錯誤.錯誤以下:

Internal Server Error


The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.

--------------------------------------------------------------------------------
Apache/2.0.52 (CentOS) Server at mail1.chinabank.com.cn Port 80
 
紅色的提示告訴咱們這個錯誤來自apache.檢查apache的錯誤日誌.
vi /var/log/httpd/error_log
 
Premature end of script headers: status.cgi, referer: [url]http://mail1.chinabank.com.cn/nagios/side.html[/url]
大意是不完整的HTTP頭.不太懂這個什麼意思.從新編譯了一個apache在/usr/local/apache/而後停掉原來的httpd,啓動新編譯的apache,發現nagios的頁面能夠正常顯示,看來是系統自帶的apache的配置有問題.google之,網上的解釋是apache啓用了suexec的功能.對CGI的執行路徑進行了限制.那麼檢查一下本機的apache是否是打開了suexec功能呢.
 
[root@mail2 ~]# httpd -V
Server version: Apache/2.0.52
Server built:   Jul 14 2007 11:53:18
Server's Module Magic Number: 20020903:9
Architecture:   32-bit
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"
看來是啓用了suexec.
運行suexec -V
能夠看到
[root@mail2 nagios]# suexec -V
 -D AP_DOC_ROOT="/var/www"
 -D AP_GID_MIN=100
 -D AP_HTTPD_USER="apache"
 -D AP_LOG_EXEC="/var/log/httpd/suexec.log"
 -D AP_SAFE_PATH="/usr/local/bin:/usr/bin:/bin"
 -D AP_UID_MIN=500
 -D AP_USERDIR_SUFFIX="public_html"
看來cgi程序只能在/var/www目錄下執行.打開/var/log/httpd/suexec.log
command not in docroot (/usr/local/nagios/sbin/status.cgi)
由於個人nagios默認安裝在/usr/local/nagios
因此這個cgi不容許被執行.
 
解決辦法.把nagios安裝到/var/www/nagios就能夠了
以前我嘗試過編譯nagios的時候指定--with-cgidir=/var/www/cgi-bin可是發現編譯好的nagios的sbin依然在/usr/local/nagios目錄下.
 
編譯的時候指定--prefix=/var/www/nagios,其餘編譯安裝的選項不變.
 
若是不想從新編譯,也能夠把原來安裝到/usr/local目錄下的
nagios移動到/var/www目錄下.再修改相關的配置文件.這個工程比較大.建議仍是從新編譯.nagios目錄下的etc目錄裏面的全部cfg的路徑都要改.能夠用vi的替換功能.
編譯好之後.重啓nagios和apache(每次進行某服務的配置文件改動後,都重啓該服務,使修改生效)
再次刷新nagios的頁面.仍是同樣的錯誤.
查看/var/log/httpd/suexec.log
 directory is writable by others: (/var/www/nagios/sbin)
目錄不能有寫權限,修改以下:
chmod -R 755 /var/www/nagios/sbin
再刷新頁面,日誌中又出現
  target uid/gid (1000/1000) mismatch with directory (1001/1001) or program (1001/1001)
apache的運行用戶和nagios的sbin目錄的屬主不匹配.
chown -R vuser.vgroup /var/www/nagios/sbin
如今好了
 
若是不修改sbin的屬主,也能夠切換apache的運行用戶.在httpd.conf中添加以下內容(添加紅色部分)
<VirtualHost *:80>
SuexecUserGroup nagios nagios
ScriptAlias /nagios/cgi-bin "/var/www/nagios/sbin"
<Directory "/var/www/nagios/sbin">
#  SSLRequireSSL
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /var/www/nagios/etc/htpasswd.users
   Require valid-user
</Directory>
Alias /nagios "/var/www/nagios/share"
<Directory "/var/www/nagios/share">
#  SSLRequireSSL
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /var/www/nagios/etc/htpasswd.users
   Require valid-user
</Directory>
</VirtualHost>
這裏必定要用VirtualHost定義一個虛擬主機,不然SuexecUserGroup nagios nagios
這條語句不起做用
而後咱們重啓apache,呵呵,總算能夠訪問nagios的監控界面了
接下來的工做就是完善nagios的監控功能.
 
總結:遇到問題後.首先應該分析是什麼問題,而後查找對應的日誌,從日誌中尋找問題的所在,對於不能理解的日誌內容,能夠google上查找答案.可是最後的解決方案仍是得本身摸索.
相關文章
相關標籤/搜索