简单的CGI脚本失败,权限被拒绝错误

时间:2019-07-09 19:32:32

标签: apache perl cgi rhel

Perl CGI脚本因

失败
Can't locate /home/testdir/first.pl:  /home/testdir/first.pl:  
Permission denied at /var/www/cgi-bin/first.cgi line 2.

End of script output before headers: first.cgi  in /etc/httpd/logs/error_log

这是具有Apache 2.4的rhel8系统

我尝试将first.pl移动到不同的位置,并修改first.cgi使其指向first.pl。 如果我将first.cgi放置在first.pl中,而不是/var/www/home/testdir或其他目录中,则/var执行

httpd.conf中,我将/home/testdir/的权限设置为与/var/www相同,如下所示,然后重新启动apache

<Directory "/home/testdir">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

出于无奈,我然后将/var/www的权限更改为Require all denied并重新启动了apache。当我将first.cgi指向first.pl并将权限更改为/var/www时,它仍然成功运行了Require all denied

在将suexec指向first.cgi时,我也禁用了/home/testdir并收到了相同的错误

first.pl/home/testdir/var/www的权限为755,用户和组均为root。

hometestdirvarwww的权限均为755,用户和组均为root用户

first.cgi

#!/usr/bin/perl
require '/home/testdir/first.pl';
test();

first.pl

#!/usr/bin/perl
sub test{
    print "Content-type: text/html\n\n";
    print "Hello, World.";
}
first;

该脚本应显示“ Hello,World”。在网页上。而是显示:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

1 个答案:

答案 0 :(得分:1)

戴夫·米切尔(Dave Mitchell)的评论正确。在命令行中输入sudo setenforce permissive后,脚本将按预期运行。