2014-07-21 26 views
2

我今天安装了一个新的CentOS 7 x86_64 LAMP服务器。Apache/httpd/var/www/html/.cgi脚本丢500内部服务器错误

我在c中编译了一个简单的CGI脚本,我将其命名为test.cgi,并且为.cgi脚本启用了AddHandler。然而,每次我尝试从/ var/www/html目录加载/test.cgi页面时,任何简单的.cgi脚本都会给我一个500内部服务器错误页面。

我测试了脚本在/ var/www/cgi-bin目录下工作正常。 我的服务器正在运行selinux,而apache/httpd正在使用suEXEC。

编辑:也没有创建任何额外的用户灯安装后,所以在这里我使用root来做所有的事情。不过,我试图解决给Apache的用户/ var/www/html目录所有权,这并没有修复悲伤。

这里的错误日志,你可以看到它给了我一个 '权限被拒绝' 的错误:

[Mon Jul 21 15:28:14.336626 2014] [core:notice] [pid 22704] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0 
[Mon Jul 21 15:28:14.339766 2014] [suexec:notice] [pid 22704] AH: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) 
[Mon Jul 21 15:28:14.495631 2014] [auth_digest:notice] [pid 22704] AH01757: generating secret for digest authentication ... 
[Mon Jul 21 15:28:14.498690 2014] [lbmethod_heartbeat:notice] [pid 22704] AH02282: No slotmem from mod_heartmonitor 
[Mon Jul 21 15:28:14.765072 2014] [mpm_prefork:notice] [pid 22704] AH00163: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16 configured -- resuming normal operations 
[Mon Jul 21 15:28:14.765186 2014] [core:notice] [pid 22704] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND' 
[Mon Jul 21 15:28:16.027553 2014] [cgi:error] [pid 22706] [client 192.168.0.68:52930] AH01215: (13)Permission denied: exec of '/var/www/html/index.cgi' failed 
[Mon Jul 21 15:28:16.030595 2014] [cgi:error] [pid 22706] [client 192.168.0.68:52930] End of script output before headers: index.cgi 
[Mon Jul 21 15:45:01.586229 2014] [mpm_prefork:notice] [pid 22704] AH00170: caught SIGWINCH, shutting down gracefully 

这是我的/ var/www/html等Apache的配置:

<Directory "/var/www/html"> 
    #                                             
    # Possible values for the Options directive are "None", "All",                             
    # or any combination of:                                       
    # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews                          
    #                                             
    # Note that "MultiViews" must be named *explicitly* --- "Options All"                            
    # doesn't give it to you.                                       
    #                                             
    # The Options directive is both complicated and important. Please see                           
    # http://httpd.apache.org/docs/2.4/mod/core.html#options                               
    # for more information.                                       
    #                                             
    Options ExecCGI FollowSymLinks 

    #                                             
    # AllowOverride controls what directives may be placed in .htaccess files.                          
    # It can be "All", "None", or any combination of the keywords:                             
    # Options FileInfo AuthConfig Limit                                    
    #                                             
    AllowOverride All 

    #                                             
    # Controls who can get stuff from this server.                                 
    #                                             
    Require all granted 
</Directory> 

而且我当然激活CGI使用:AddHandler cgi-script .cgi .pl

这是我简单test1.c文件:

#include <stdio.h> 

int main(void) { 
    puts("Content-Type: text/html; charset=ISO-8859-1\n"); 
    fputs("Hello, World!", stdout); 

    return 0; 
} 

输出是正确:Content-Type: text/html; charset=ISO-8859-1\n\nHello, World!

而且我用gcc编译它,然后把它的权限777 test.cgi 你知道什么,我需要做的解决这一问题?

由于提前, Zorgatone

+0

我与Centos 7上的CGI脚本有同样的问题。我正在尝试安装Bugzilla。我已经尝试了所有不同的权限,包括删除写入权限并将所有者切换到apache.apache,但都没有效果。 –

+0

500错误非常普遍...检查日志 – user83039

回答

0

我刚刚解决了重新安装服务器,并做一遍所有,禁用SELinux和iptables的,因为我已经有一个外部防火墙。

由于任何人谁帮我出;)

1

我不知道这对你是一个可行的解决方案,但我得到了它改变了SELinux,以宽容的工作。以下是您感兴趣的步骤。

vi /etc/selinux/config 

更改以下行:

SELINUX=enforcing 

到:

SELINUX=permissive 
0

这很可能是一个SELinux的问题(其中汤姆·斯威尼answer提供了一个解决方案,使用许可SELinux和自己的接受answer您表示完全禁用SELinux) 。另一种方法是为您的CGI文件配置适当的SELinux类型(以及可能的其他策略更改)。


要开始了,安装的SELinux策略管理工具(如果尚未完成):

sudo yum install policycoreutils-python 

假设你想允许在您的/var/www/html目录中的所有基于CGI的文件,你可以使用以下命令将httpd_sys_script_exec_t背景下适用于当前和未来的CGI文件:

sudo semanage fcontext -a -t httpd_sys_script_exec_t '/var/www/html(/.*)?/.*\.cgi' 

接下来,还原任何现有的CGI FIL内容ES:

sudo restorecon -Rv /var/www/html/ 

您还需要允许Apache将允许执行CGI脚本使用下列内容:

sudo setsebool -P httpd_enable_cgi 1 

你应该做的。请注意,如果您的CGI脚本需要读取/写入系统中其他文件的内容,则还必须将httpd_sys_rw_content_t上下文应用于这些文件(请参阅下面的示例)。


刚刚遇到这个问题,试图在CentOS 7(x86_64)系统上安装Bugzilla(使用CGI)。监控我的httpd的错误日志(sudo tail -f /var/log/httpd/error_log)当观察到以下错误:

[cgi:error] [pid 1825] [client ...:56481] AH01215: (13)Permission denied: exec of '/var/www/html/bugzilla/index.cgi' failed 
[cgi:error] [pid 1825] [client ...:56481] End of script output before headers: index.cgi 

检查范围内的应用到我的Bugzilla的安装,我看到以下内容:

$ ls -Z /var/www/html/bugzilla/ 
... 
-rwxr-x---. apache apache unconfined_u:object_r:httpd_sys_content_t:s0 index.cgi 
... 

然后我用下面的命令许可证Bugzilla的CGI脚本执行以及用于访问表示CGI脚本读取./data目录中的内容:

sudo yum install policycoreutils-python 
sudo semanage fcontext -a -t httpd_sys_script_exec_t '/var/www/html/bugzilla(/.*)?/.*\.cgi' 
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/bugzilla/data(/.*)?' 
sudo restorecon -Rv /var/www/html/bugzilla/ 
sudo setsebool -P httpd_enable_cgi 1 

检查应用的上下文显示期望的结果:

$ ls -Z /var/www/html/bugzilla/ 
... 
-rwxr-x---. apache apache unconfined_u:object_r:httpd_sys_script_exec_t:s0 index.cgi 
... 

Bugzilla应该现在可用。 Bugzilla提供的所有功能可能还有其他策略可以应用;但是,如果需要任何其他策略,我不知道。