【发布时间】:2019-11-19 10:00:54
【问题描述】:
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.pl 放在/var/www 中,first.cgi 就会执行,而不是/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 指向/var/www 并将权限更改为Require all denied 时,first.cgi 仍然成功运行first.pl。
我还禁用了suexec,并在将first.cgi 指向/home/testdir 时收到了同样的错误
first.pl 在/home/testdir 和/var/www 中的权限是755,用户和组都是root。
home、testdir、var和www的权限都是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.
【问题讨论】:
-
first.pl最后一行的first子在哪里定义? -
问个问题,2019年你为什么用
cgi?:) -
这将是一个 UNIX 权限/ACL/SELinux 问题。运行 apache 进程的 id 没有对 first.pl 的读取权限和/或中间目录的搜索权限。事实上,如果您的服务器正在运行 SELinux,那么通常会进行设置,这样 apache 进程就无法访问 /var/www 等之外的任何内容。
-
我正在运行 CGI,因为我继承了某些还没有可用的现代替代品的任务。这只是我编写的一个示例脚本,用于调试我将它们移植到 rhel8 的问题。
-
我实际上成功地将脚本作为 apache 运行 sudo -u apache ./first.cgi 以检查 Linux 权限。