2009-10-21 253 views
15

我第一次尝试CGI脚本但没有成功。我已阅读了许多教程,并在不同的论坛中遵循了可能的线程,但我无法使其工作。 我在Fedora 10机器上使用appache web服务器。 我总是有问题(13)权限被拒绝:访问/cgi-bin/test.cgi被拒绝

[Wed Oct 21 20:47:36 2009] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0 
[Wed Oct 21 20:47:36 2009] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) 
[Wed Oct 21 20:47:36 2009] [notice] Digest: generating secret for digest authentication ... 
[Wed Oct 21 20:47:36 2009] [notice] Digest: done 
[Wed Oct 21 20:47:36 2009] [notice] Apache/2.2.11 (Unix) DAV/2 PHP/5.2.9 mod_ssl/2.2.11 OpenSSL/0.9.8g configured -- resuming normal operations 

我需要帮助。 这就是我的环境。

uname -a 
Linux localhost.localdomain 2.6.27.5-117.fc10.i686 #1 SMP Tue Nov 18 12:19:59 EST 2008 i686 i686 i386 GNU/Linux 

ls -l /var/www/cgi-bin/ 
total 36 
-rwxrwxrwx 1 root root 106 2009-10-21 18:29 index.html 
-rwxr-xr-x 1 root root 11089 2009-02-24 20:11 squidGuard.cgi 
-rwxr-xr-x 1 root root 5720 2009-02-24 20:11 squidGuard-simple.cgi 
-rwxr-xr-x 1 root root 5945 2009-02-24 20:11 squidGuard-simple-de.cgi 
-rwxrwxrwx 1 root root 110 2009-10-21 17:38 test.cgi 

apachectl -v 
Server version: Apache/2.2.11 (Unix) 
Server built: Mar 6 2009 09:12:25 

perl -version 
This is perl, v5.10.0 built for i386-linux-thread-multi 
Copyright 1987-2007, Larry Wall 

我的脚本

cat test.cgi 
#!/usr/bin/perl 
print "Content-Type: text/html\n\n"; 
print "Hello, world!\n"; 

该错误消息我创,当我尝试访问该网页服务器“http://192.168.50.29/cgi-bin/test.cgi”看起来是这样的:

[Wed Oct 21 21:00:27 2009] [error] [client 192.168.50.69] (13)Permission denied: access to /cgi-bin/test.cgi denied 

我已经添加了一行:

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" 

到/etc/httpd/conf/httpd.conf

我只是不能让它工作。 任何人都可以帮助我吗?

+0

该错误消息我创,当我尝试访问该网页服务器“http://192.168.50.29/test。cgi“看起来像这样: [Wed Oct 21 22:31:32 2009] [error] [client 192.168.50.69](13)Permission denied:exec of'/var/www/html/test.cgi'failed [Wed Oct 21 22:31:32 2009] [error] [client 192.168.50.69]脚本标题提前结束:test.cgi – 2009-10-21 11:19:44

+1

为什么哦,为什么root拥有这些文件? – 2009-10-31 13:18:19

+0

找出哪个用户/组拥有apache服务器进程并确保它拥有你的CGI脚本并拥有exec权限 – heferav 2009-10-31 14:20:58

回答

11

检查你的os权限test.cgi,并确保你正在使用的用户或组来运行你的apache它有读权限。

编辑 - 问题与权限有关,但与读取权限无关,因为您使用的是SELinux,所以您需要担心文件上下文。在fedora论坛上检查这个thread,它解释了很多选项来解决你的问题。

+0

根据问题test.cgi拥有777个权限 - 即读,写,执行用户,组和其他 - 所有用户都可以做任何事情 – 2009-10-21 09:54:22

+0

真的,我在第一次阅读时忽略了这一点,使用未格式化的代码。 – pedromarce 2009-10-21 10:15:28

5

首先检查HTTPD.CONF文件。在httpd.conf中按如下所示设置脚本目录。
在这里,您需要确保找到正确的httpd.conf文件。例如,在我的Debian中,默认的httpd.conf是/ etc/apache2/sites-avaialbe/default。

 
<Directory "dir_name"> 
    Options All 
    AllowOverride All 
    Order allow,deny 
    Allow from all 
<Directory> 

OR你可以只使用默认的/ cgi-bin文件夹。

。为测试脚本设置执行权限

 
chmod +x script_name 
+1

facepalm,在我的情况下忘记了执行权限 – elhombre 2015-12-08 15:15:16

4

检查你的fstab如果挂载文件系统有权执行

UUID=xxx-xxx-xxx-xx-xx  /mnt/mountpoint  ext4  rw,user,exec  0  0 

EXEC部分是很重要的

4

的SELinux防止阿帕奇从我的情况下访问CGI脚本。 快速正肮脏的修复,对我的工作是关闭SELinux的:

vim /etc/sysconfig/selinux 
set "SELINUX=disabled" 
reboot 
+1

好吧,现在你的问题是你没有运行wi thin SELinux;)我相信你的情况下,你已经在另一个位置创建了一个cgi-bin目录,这意味着你必须使用命令'semange fcontext -a -t httpd_sys_script_exec_t“/添加一个新的文件上下文到策略列表中path/to/directory(/.*)?'',然后'restorecon -Rv/path/to/directory'将新的文件上下文应用于文件。查看man semanage-fcontext并进入示例部分,这里有一个很好的例子。 – elhombre 2015-12-08 15:25:45