Linux Apache/httpd/var/www/html/.cgi脚本引发500个内部服务器错误

Linux Apache/httpd/var/www/html/.cgi脚本引发500个内部服务器错误,linux,apache,centos,cgi,Linux,Apache,Centos,Cgi,我今天安装了一个新的CentOS 7 x86_64 LAMP服务器 我用c编译了一个简单的CGI脚本,我称之为test.CGI,并为.CGI脚本启用了AddHandler。但是,每次我尝试从/var/www/html目录加载/test.cgi页面时,任何简单的.cgi脚本都会抛出500个内部服务器错误页面 我在/var/www/cgi-bin目录下测试了脚本是否工作正常。 我的服务器运行的是selinux,apache/httpd使用的是suEXEC 编辑:在lamp安装之后,我也没有创建任何额

我今天安装了一个新的CentOS 7 x86_64 LAMP服务器

我用c编译了一个简单的CGI脚本,我称之为test.CGI,并为.CGI脚本启用了AddHandler。但是,每次我尝试从/var/www/html目录加载/test.cgi页面时,任何简单的.cgi脚本都会抛出500个内部服务器错误页面

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

编辑:在lamp安装之后,我也没有创建任何额外的用户,所以现在我使用root来完成所有工作。然而,我试图修复将/var/www/html目录所有权授予apache用户的问题,但遗憾的是,这并没有解决问题

这是错误日志,您可以看到它给了我一个“权限被拒绝”错误:

[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] AH01232: 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>
输出正确:
内容类型:text/html;charset=ISO-8859-1\n\n Hello,世界

我还用gcc编译了它,然后授予它test.cgi的777权限 你知道我需要做什么来解决这个问题吗

提前感谢,,
Zorgatone

我不确定这对您来说是否是一个可行的解决方案,但我通过将SELinux更改为permissive来实现它。以下是你感兴趣的步骤

vi /etc/selinux/config
更改以下行:

SELINUX=enforcing
致:


我刚刚解决了重新安装服务器的问题,重新开始,禁用了selinux和iptables,因为我已经有了一个外部防火墙


感谢所有帮助我的人;)

这很可能是一个SELinux问题(Tom Sweeney提供了一个使用许可SELinux的解决方案,您自己也接受了该解决方案,您表示要完全禁用SELinux)。另一种方法是为CGI文件配置适当的SELinux类型(可能还有其他策略更改)


首先,安装SELinux策略管理工具(如果尚未安装):

假设希望允许
/var/www/html
目录中的所有基于CGI的文件,可以使用以下命令将上下文应用于当前和未来的CGI文件:

sudo semanage fcontext -a -t httpd_sys_script_exec_t '/var/www/html(/.*)?/.*\.cgi'
sudo restorecon -Rv /var/www/html/
接下来,还原任何现有CGI文件的内容:

sudo semanage fcontext -a -t httpd_sys_script_exec_t '/var/www/html(/.*)?/.*\.cgi'
sudo restorecon -Rv /var/www/html/
您还需要允许Apache允许使用以下命令执行CGI脚本:

sudo setsebool -P httpd_enable_cgi 1
$ ls -Z /var/www/html/bugzilla/
...
-rwxr-x---. apache apache unconfined_u:object_r:httpd_sys_content_t:s0 index.cgi
...
你应该完蛋了。请注意,如果您的CGI脚本需要从系统中的其他文件读取/写入内容,您还必须将
httpd\u sys\u rw\u content\t
上下文应用于这些文件(参见下面的示例)


刚刚在CentOS 7(x86_64)系统上安装Bugzilla(使用CGI)时遇到了这个问题。监视我的httpd错误日志时发现以下错误(
sudo tail-f/var/log/httpd/error\u log
):

检查应用于Bugzilla安装的上下文,我看到以下内容:

sudo setsebool -P httpd_enable_cgi 1
$ 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提供的所有功能,可能会有其他政策适用;但是,我不知道是否需要任何其他策略。

我在Centos 7上的cgi脚本也有同样的问题。我正在尝试安装Bugzilla。我尝试了所有不同的权限,包括删除写访问权限和将所有者切换到apache.apache,但这两种权限似乎都不起作用。500错误非常普遍。。。检查日志