简体   繁体   English

cgi脚本无法在apache下写入世界可写文件

[英]cgi script can't write to world writable file under apache

I'm attempting to create a simple CGI script using CentOS 7, Apache 2.4 and Ruby 2.0. 我正在尝试使用CentOS 7,Apache 2.4和Ruby 2.0创建一个简单的CGI脚本。 All tools installed from official packages. 从官方软件包安装的所有工具。

My script, which resides at /var/www/cgi-bin/test.cgi is: 我的脚本位于/var/www/cgi-bin/test.cgi ,它是:

#!/usr/bin/ruby

puts "Content-Type: text/plain\n\n"
begin
    file = File.open("test.log", "a")
    file.puts("foobar")
    file.close
rescue Exception
    puts "pwd: #{`pwd`}"
    puts $!.inspect
end

When I load http://myhost/cgi-bin/test.cgi , I get the following: 当我加载http://myhost/cgi-bin/test.cgi ,我得到以下信息:

pwd: /var/www/cgi-bin
#<Errno::EACCES: Permission denied - test.log>

However: 然而:

[root@host cgi-bin]# ls -l /var/www/cgi-bin
total 8
-rwxr-xr-x. 1 root root 153 Jul 10 22:03 env.cgi
-rwxr-xr-x. 1 root root 359 Jul 11 00:45 test.cgi
-rw-rw-rw-. 1 root root   0 Jul 11 00:42 test.log

How (and where) can I write data from inside this cgi script if not to a world-writable file in the script's own working directory? 如果不从CGI脚本内部将数据写入脚本自己的工作目录中的世界可写文件,该如何(在何处)写入数据?

SELinux was blocking the file writes. SELinux阻止了文件写入。 "setenforce Permissive" allowed them to go through. “ setenforce Permissive”允许他们通过。 Edited /etc/sysconfig/selinux and rebooted to make permanent. 编辑/ etc / sysconfig / selinux并重新启动以使其永久。

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

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