>>分享Java Web开发技术,并且对孙卫琴的《Tomcat与Java Web开发技术详解》提供技术支持 书籍支持  卫琴直播  品书摘要  在线测试  资源下载  联系我们
发表一个新主题 开启一个新投票 回复文章 您是本文章第 21578 个阅读者 刷新本主题
 * 贴子主题:  Apache Internal Server Error 解决方法 回复文章 点赞(0)  收藏  
作者:flybird    发表时间:2020-01-27 17:56:34     消息  查看  搜索  好友  邮件  复制  引用

今天配置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: http://mail1.chinabank.com.cn/nagios/side.html

     大意是不完整的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上查找答案.但是最后的解决方案还是得自己摸索.


----------------------------
原文链接:https://blog.51cto.com/coolerfeng/47635
原作者:风吹云动
程序猿的技术大观园:www.javathinker.net



[这个贴子最后由 flybird 在 2020-01-29 15:11:31 重新编辑]
网站系统异常


系统异常信息
Request URL: http://www.javathinker.net/WEB-INF/lybbs/jsp/topic.jsp?postID=1646

java.lang.NullPointerException

如果你不知道错误发生的原因,请把上面完整的信息提交给本站管理人员