“您没有访问此资源的权限,”适用于Mac OS 11 - Big Sur上CGI-可执行文件/中的perl脚本

qgelzfjb  于 2022-11-15  发布在  Perl
关注(0)|答案(1)|浏览(155)

我在Mac OS 11 - Big Sur上的/Library/WebServer/CGI-Executables/中收到Perl脚本的“You don 't have permission to access this resource.”(您没有访问此资源的权限)。我有一个简单的测试脚本:

#!/usr/bin/perl
print "Content-type: text/html; charset=iso-8859-1\n\n";
print "<html>";
print "<body>";
print "Test Page";
print "</body>";
print "</html>";
print "\n";

当我从Terminal执行它时,它运行正常,输出为:

Content-type: text/html; charset=iso-8859-1

<html><body>Test Page</body></html>

我相信脚本的文件权限为:

-rwxr-xr-x   1 <my-username>  wheel    170 Aug 31 04:50 test.pl*

是正确的。
我认为脚本所在目录的文件权限:

drwxr-xr-x  24 <my-username>  wheel   768 Aug 31 18:52 CGI-Executables/

也是正确的。
我相信我的httpd.conf配置正确:

<IfModule !mpm_prefork_module>
        #LoadModule cgid_module lib/httpd/modules/mod_cgid.so                                                                                                          
</IfModule>
<IfModule mpm_prefork_module>
        LoadModule cgi_module lib/httpd/modules/mod_cgi.so
</IfModule>

ScriptAlias /cgi-bin/ "/Library/WebServer/CGI-Executables"

<Directory "/Library/WebServer/CGI-Executables">
    AddHandler cgi-script .cgi .pl .pm
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride None
    Allow from all
    Require all granted
</Directory>

虽然我相信所有这些都是正确的,但很明显,这些信念中有一个或多个是错误的,因为当我尝试使用http://localhost/cgi-bin/test.pl在Web浏览器中打开test.pl时,我得到错误消息:

Forbidden

You don't have permission to access this resource.

编辑

在@ikegami建议我查看日志后,我在/usr/local/var/log/httpd/error_log中发现:
[Sat Sep 03 07:55:17.605501 2022] [authz_core:error] [pid 3035] [client ::1:61483] AH01630: client denied by server configuration: /Library/WebServer/CGI-Executablestest.pl
这使我想到了Apache2: 'AH01630: client denied by server configuration',并建议我修改我的httpd.conf,添加:

Order allow,deny

因此,现在我的httpd.conf看起来像:

ScriptAlias /cgi-bin/ "/Library/WebServer/CGI-Executables"

<Directory "/Library/WebServer/CGI-Executables">
    AddHandler cgi-script .cgi .pl .pm
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride None
    Allow from all
    Order allow,deny
    Require all granted
</Directory>

但是在brew services restart httpd之后,我仍然得到上面的AH01630错误。

ukqbszuj

ukqbszuj1#

这是一种注重细节的考验。
看看这最后

3035] [client ::1:61483] AH01630: client denied by server configuration: /Library/WebServer/CGI-Executablestest.pl

看看这个

ScriptAlias /cgi-bin/ "/Library/WebServer/CGI-Executables"

并将其更改为

ScriptAlias /cgi-bin/ "/Library/WebServer/CGI-Executables/"

相关问题