提问人:SB121 提问时间:9/7/2023 更新时间:9/7/2023 访问量:34
CGI perl 脚本无法写入文件
CGI perl script can't write to file
问:
我在 Centos 7 上运行 Apache 2.4。我已经花了一个星期的时间解决这个问题,它变得压力很大(这是一个测试文件,我正在为第三方设置访问权限,以便能够写入服务器上的文件并创建它来复制问题)。
该脚本从 /home/sle/domains/mydomain.com/public_html/cgi-bin/GzK8PhiWEfM9c4jZgyNrpYb5RtnD3ex6/test 运行.cgi
#!/usr/bin/perl
use strict;
use warnings;
use CGI ":standard";
print "Content-type:text/html \n\n";
open (FILE, '>', "/home/sle/domains/mydomain.com/public_html/test.txt") or die ("Could not open the file for writing...$!");
print FILE "something";
close(FILE);
错误消息显示“内部服务器错误”,错误日志中的消息显示:
[星期四 9月 07 01:07:37.226029 2023][cgi:错误][PID 28876][客户端 2.221.192.244:56475]AH01215:(8)exec 格式错误:“/home/sle/domains/mydomain.com/public_html/cgi-bin/GzK8PhiWEfM9c4jZgyNrpYb5RtnD3ex6/test.cgi”的 exec 失败:/home/sle/domains/mydomain.com/public_html/cgi-bin/GzK8PhiWEfM9c4jZgyNrpYb5RtnD3ex6/test.cgi [Thu Sep 07 01:07:37.226322 2023][cgi:错误][PID 28876][客户端 2.221.192.244:56475]在标头之前结束脚本输出:test.cgi
此脚本运行正常:
#!/usr/bin/perl
use strict;
use warnings;
print "Content-type: text/html\n\n";
print "Hello World!";
我可以将test.txt放在任何文件夹中,也会发生同样的事情。cgi-bin 文件夹归 apache 所有,但如果它归 root 和 sle 所有,并且所有文件都是 777,它仍然会发生。问题似乎出在尝试写入文件时。
这是虚拟主机
<VirtualHost myipaddress:80 >
ServerName www.mydomain.com
ServerAlias www.mydomain.com mydomain.com
ServerAdmin [email protected]
DocumentRoot /home/sle/domains/mydomain.com/public_html
ScriptAlias /cgi-bin/ /home/sle/domains/mydomain.com/public_html/cgi-bin/
UseCanonicalName OFF
<Directory "/home/sle/domains/mydomain.com/public_html/cgi-bin/">
Options +ExecCGI +Indexes +MultiViews
Options FollowSymLinks
SetHandler cgi-script
Require all granted
</Directory>
<IfModule !mod_ruid2.c>
SuexecUserGroup sle sle
</IfModule>
<IfModule mod_ruid2.c>
RMode config
RUidGid sle sle
#RGroups apache access
RGroups @none
</IfModule>
CustomLog /var/log/httpd/domains/mydomain.com.bytes bytes
CustomLog /var/log/httpd/domains/mydomain.com.log combined
ErrorLog /var/log/httpd/domains/mydomain.com.error.log
<Directory /home/sle/domains/mydomain.com/public_html>
php_admin_flag engine ON
php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f [email protected]'
php_admin_value mail.log /home/sle/.php/php-mail.log
</Directory>
</VirtualHost>
<VirtualHost myipaddress:443 >
SSLEngine on
SSLCertificateFile /home/sle/domains/mydomain.com/cert/mydomain.com.crt
SSLCertificateKeyFile /home/sle/domains/mydomain.com/cert/mydomain.com.key
SSLCACertificateFile /home/sle/domains/mydomain.com/cert/mydomain.com.crt
ServerName www.mydomain.com
ServerAlias www.mydomain.com mydomain.com
ServerAdmin [email protected]
DocumentRoot /home/sle/domains/mydomain.com/public_html
ScriptAlias /cgi-bin/ /home/sle/domains/mydomain.com/public_html/cgi-bin/
<Directory "/home/sle/domains/mydomain.com/public_html/cgi-bin/">
Options +ExecCGI +Indexes +MultiViews
Options FollowSymLinks
SetHandler cgi-script
Require all granted
</Directory>
UseCanonicalName OFF
<IfModule !mod_ruid2.c>
SuexecUserGroup sle sle
</IfModule>
<IfModule mod_ruid2.c>
RMode config
RUidGid sle sle
#RGroups apache access
RGroups @none
</IfModule>
CustomLog /var/log/httpd/domains/mydomain.com.bytes bytes
CustomLog /var/log/httpd/domains/mydomain.com.log combined
ErrorLog /var/log/httpd/domains/mydomain.com.error.log
<Directory /home/sle/domains/mydomain.com/private_html>
php_admin_flag engine ON
php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f [email protected]'
php_admin_value mail.log /home/sle/.php/php-mail.log
</Directory>
</VirtualHost>
我将文件移动到多个位置,更改了所有权,更改了权限,并在虚拟主机中添加了该行。
答: 暂无答案
评论
#!
perl test.cgi