我今天安装了一台新的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 .
编辑:我也没有在灯安装后创建任何额外的用户,所以在这里我使用root来做现在的一切 . 但是我试图修复将/ var / www / html目录所有权给予apache用户,这并没有令人遗憾 .
这是错误日志,因为你可以看到它给了我一个'Permission Denied'错误:
[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>
当然我用以下方法激活了CGI: AddHandler cgi-script .cgi .pl
这是我简单的test.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
3 回答
我不确定这是否是一个可行的解决方案,但我通过将SELinux更改为允许来实现它 . 以下是您感兴趣的步骤 .
更改以下行:
至:
我刚刚解决了重新安装服务器并重新做一遍,禁用selinux和iptables,因为我已经有了一个外部防火墙 .
感谢任何帮助过我的人;)
这很可能是一个SELinux问题(Tom Sweeney answer提供了一个解决方案,使用一个允许的SELinux和你自己接受的answer,你指示完全禁用SELinux) . 另一种方法是为CGI文件配置适当的SELinux类型(以及可能的其他策略更改) .
首先,安装SELinux策略管理工具(如果尚未完成):
假设您要允许
/var/www/html
目录中的所有基于CGI的文件,可以使用以下命令将httpd_sys_script_exec_t上下文应用于当前和未来的CGI文件:接下来,恢复任何现有CGI文件的内容:
您还需要允许Apache允许使用以下命令执行CGI脚本:
你应该完成 . 请注意,如果您的CGI脚本需要从系统中的其他文件读取/写入内容,您还必须同时将
httpd_sys_rw_content_t
上下文应用于这些文件(请参阅下面的示例) .刚刚在CentOS 7(x86_64)系统上尝试安装Bugzilla(使用CGI)时遇到了这个问题 . 监视我的httpd错误日志(
sudo tail -f /var/log/httpd/error_log
)时发现以下错误:检查应用于我的Bugzilla安装的上下文,我看到以下内容:
然后,我使用以下命令允许执行Bugzilla的CGI脚本以及访问所述CGI脚本以读取
./data
目录中的内容:检查应用的上下文显示了所需的结果:
Bugzilla现在应该可用了 . 可能还有其他政策适用于Bugzilla提供的所有功能;但是,我不知道是否需要任何其他政策 .