简体   繁体   English

Apache2 CGI 执行权限被拒绝

[英]Apache2 CGI Execution Permission Denied

I am getting this error when I try executing a basic Perl script on my Apache server.当我尝试在我的 Apache 服务器上执行基本 Perl 脚本时出现此错误。 In my browser, I type in localhost/cgi-bin/first.pl , and I receive this error:在浏览器中,我输入localhost/cgi-bin/first.pl ,然后收到此错误:

(13)Permission denied: exec of '/usr/lib/cgi-bin/first.pl' failed (13)权限被拒绝:'/usr/lib/cgi-bin/first.pl'的exec失败

This is my perl script:这是我的 perl 脚本:

#!/usr/lib/cgi-bin

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

And this is my default file in the sites-available folder.这是我在sites-available文件夹中的默认文件。 As you can see, every file in /usr/lib/cgi-bin should be recognized as a CGI file.如您所见, /usr/lib/cgi-bin每个文件都应该被识别为 CGI 文件。 And, /usr/lib/cgi-bin is exactly where first.pl is located.而且, /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>

ALSO, I did do chmod a+x first.pl .另外,我确实做了chmod a+x first.pl

You are getting this error because the shebang line (the first line of the script, starting with #! ) specifies the interpreter that is launched to execute the script.您收到此错误是因为 shebang 行(脚本的第一行,以#!开头)指定了为执行脚本而启动的解释器。 What failed was therefore launching /usr/lib/cgi-bin as an executable.因此失败的是将/usr/lib/cgi-bin作为可执行文件启动。

Replace代替

#!/usr/lib/cgi-bin

with

#!/usr/bin/perl

If that still doesn't work, one possibility is that perl is in an ununsual location, and you could try如果这仍然不起作用,一种可能是perl位于不寻常的位置,您可以尝试

#!/usr/bin/env perl

One suggestion, if you can use a shell on the machine where your script lives, would be to try executing it directly.一个建议,如果您可以在脚本所在的机器上使用 shell,则尝试直接执行它。 Had you done this, you would have seen a slightly more explanatory message "bad interpreter: Permission denied".如果你这样做了,你会看到一个稍微解释性更强的消息“bad interpreter: Permission denied”。

Check your permission/owner information on the directory as well.还要检查您对目录的许可/所有者信息。

Looking at the apache conf you posted, you will need to change the script to have a .cgi extension or add the perl extension to the AddHandler.查看您发布的 apache conf,您需要将脚本更改为具有 .cgi 扩展名或将 perl 扩展名添加到 AddHandler。 What you have provided only lists the python extension.您提供的内容仅列出了 python 扩展名。

I had this problem with the http/cgi wrapper for git.我在 git 的 http/cgi 包装器上遇到了这个问题。

For me the issue was mod_cgid and the permissions on /var/run preventing cgid from attaching to the socket used for the cgi script.对我来说,问题是 mod_cgid 和 /var/run 上的权限阻止 cgid 附加到用于 cgi 脚本的套接字。

The rather cryptic clue was相当神秘的线索是

[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

Yet www-data can run the git-http-backend cgi executable然而 www-data 可以运行 git-http-backend cgi 可执行文件

I resolved this by creating folder /apache_run with permissions www_data:www_data 770 and adding the following to apache2.conf我通过创建具有 www_data:www_data 770 权限的文件夹 /apache_run 并将以下内容添加到 apache2.conf 解决了这个问题

ScriptSock /apache2_run/cgid.sock

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM