Apache2 CGI执行权限被拒绝

时间:2014-05-27 02:18:07

标签: perl permissions apache2 cgi execution

当我尝试在Apache服务器上执行基本Perl脚本时出现此错误。在我的浏览器中,我输入localhost/cgi-bin/first.pl,我收到此错误:

  

(13)权限被拒绝:'/usr/lib/cgi-bin/first.pl'的执行失败

这是我的perl脚本:

#!/usr/lib/cgi-bin

print "Content-type: text/html\n\n";
print "Hello, World.";

这是sites-available文件夹中的默认文件。如您所见,/usr/lib/cgi-bin中的每个文件都应该被识别为CGI文件。而且,/usr/lib/cgi-bin正好是first.pl所在的位置。

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

DocumentRoot /home/www
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /home/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AddHandler cgi-script .cgi .py
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

另外,我做过chmod a+x first.pl

3 个答案:

答案 0 :(得分:1)

您收到此错误是因为shebang行(脚本的第一行,以#!开头)指定了为执行脚本而启动的解释器。因此失败的是将/usr/lib/cgi-bin作为可执行文件启动。

替换

#!/usr/lib/cgi-bin

#!/usr/bin/perl

如果仍然不起作用,一种可能性是perl处于无意义的位置,您可以尝试

#!/usr/bin/env perl

一个建议是,如果你可以在你的脚本所在的机器上使用shell,那么就是尝试直接执行它。如果你这样做了,你会看到一个稍微更具解释性的信息&#34;糟糕的翻译:权限被拒绝&#34;。

答案 1 :(得分:0)

同时检查您的权限/所有者信息。

查看您发布的apache conf,您需要更改脚本以具有.cgi扩展名或将perl扩展名添加到AddHandler。你提供的只列出了python扩展名。

答案 2 :(得分:0)

我在git的http / cgi包装器中遇到了这个问题。

对我来说,问题是mod_cgid和/ var / run上的权限阻止cgid附加到用于cgi脚本的套接字上。

比较隐秘的线索是

[Fri Nov 27 14:39:02.506675 2020] [cgid:error] [pid 589971:tid 140310986311424] (13)Permission denied: [client 172.16.90.189:50018] AH01257: unable to connect to cgi daemon after multiple tries: /usr/lib/git-core/git-http-backend

但是www-data可以运行git-http-backend cgi可执行文件

我通过创建具有权限www_data:www_data 770的/ apache_run文件夹解决了此问题 并将以下内容添加到apache2.conf

ScriptSock /apache2_run/cgid.sock
相关问题