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上查找答案.可是最后的解决方案仍是得本身摸索.
相关文章
相关标签/搜索