【发布时间】:2014-09-12 02:06:06
【问题描述】:
我今天安装了一个新的 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 用户的问题,但遗憾的是没有解决。
这是错误日志,如您所见,它给了我一个“权限被拒绝”错误:
[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 你知道我需要做什么来解决这个问题吗?
提前致谢, 佐加托内
【问题讨论】:
-
我在 Centos 7 上的 cgi 脚本遇到了同样的问题。我正在尝试安装 Bugzilla。我已经尝试了所有不同的权限,包括删除写入权限和将所有者切换到 apache.apache,但似乎都不起作用。
-
500 错误非常普遍...检查日志