【问题标题】:Apache2 CGI Execution Permission DeniedApache2 CGI 执行权限被拒绝
【发布时间】:2014-07-15 19:37:51
【问题描述】:

当我尝试在我的 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

【问题讨论】:

  • 脚本上的 shebang 不是脚本的位置...它是脚本解释器的位置。

标签: perl permissions apache2 cgi execution


【解决方案1】:

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

替换

#!/usr/lib/cgi-bin

#!/usr/bin/perl

如果这仍然不起作用,一种可能是perl 位于不寻常的位置,您可以尝试

#!/usr/bin/env perl

如果您可以在脚本所在的机器上使用 shell,一个建议是尝试直接执行它。如果您这样做了,您会看到一条解释性稍强的消息“bad interpreter: Permission denied”。

【讨论】:

  • 成功了!谢谢!我把它改成了#! /usr/bin/evn perl,它工作得很好
【解决方案2】:

还要检查您对该目录的权限/所有者信息。

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

【讨论】:

  • 是的,我刚刚注意到了。修复了它,但仍然没有运气。
  • 我在我的 apache2 和 cgi-bin 文件夹上都尝试了递归 chmod 755 和 777,但我仍然得到相同的权限错误。
【解决方案3】:

我在使用 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-15
    • 2013-04-14
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 1970-01-01
    • 2016-12-25
    相关资源
    最近更新 更多