我的 cgi 脚本无法写入 Apache 的 cgi-bin 文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1635921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
My cgi script can't write to cgi-bin folder of Apache
提问by Yinan
I m working on a python version cgi script which needs to create img files (which will be shown on the web page) in cgi-bin folder.
我正在开发一个 python 版本的 cgi 脚本,它需要在 cgi-bin 文件夹中创建 img 文件(将显示在网页上)。
But it fails with: [Wed Oct 28 16:13:51 2009] [error] [client ::1] OSError: [Errno 13] Permission denied: 'average/'
但它失败了:[Wed Oct 28 16:13:51 2009] [error] [client ::1] OSError: [Errno 13] Permission denied: 'average/'
[Note] 'average/' is the folder that the cgi script is going to create first for saving those img files.
[注意] 'average/' 是 cgi 脚本首先要创建的文件夹,用于保存那些 img 文件。
I tried giving a+x permission to the cgi script, but it failed still. This happens on both Win and Mac.
我尝试为 cgi 脚本授予 a+x 权限,但它仍然失败。这发生在 Win 和 Mac 上。
Btw, I m working with the default Apache configurations. I didn't change anything after the installation of Apache.
顺便说一句,我正在使用默认的 Apache 配置。安装Apache后我没有改变任何东西。
回答by bobince
You would have to give the web server user write permission to the cgi-bin folder. Usually the web server user is something like nobodyand not in the same group as the owner of the folder, so that means making cgi-bin world-writable: Note: This is a really bad idea.
您必须授予 Web 服务器用户对 cgi-bin 文件夹的写权限。通常,Web 服务器用户nobody与文件夹的所有者类似但不在同一组中,因此这意味着使 cgi-bin 可全局写入: 注意:这是一个非常糟糕的主意。
chmod a+rwx cgi-bin
(or, on Windows setting permissions on cgi-bin to give Everyone ‘Full Control'.)
(或者,在 Windows 上设置 cgi-bin 权限以赋予每个人“完全控制权”。)
Now any user on your server, or any script that doesn't check its filenames properly, might create a file in the cgi-bin, where it will be interpreted by Apache as a CGI script and executed. This is a good way to get your server owned.
现在,您服务器上的任何用户,或任何未正确检查其文件名的脚本,都可能在 cgi-bin 中创建一个文件,Apache 将在该文件中将其解释为 CGI 脚本并执行。这是让您拥有服务器的好方法。
Run-time-written files should go in a separate ‘data' folder, outside the cgi-bin (and preferably outside the web root, bound with an Alias), with Apache set to disallow any kind of script or htaccess from that folder. You can then set ‘data' 777, or, possibly better, have it owned by the web server user instead.
运行时写入的文件应该放在 cgi-bin 之外的单独的“data”文件夹中(最好在 web 根之外Alias,用 . 然后,您可以设置 'data' 777,或者,可能更好,让 Web 服务器用户拥有它。
回答by pavium
The error message is complaining about permissions for the folder average/not the cgi file.
错误消息是抱怨文件夹的权限而average/不是 cgi 文件。
EDIT: So your python script (which runs on both Win and Mac) is responsible for creating the folder and the img files?
编辑:所以你的 python 脚本(在 Win 和 Mac 上运行)负责创建文件夹和 img 文件?
You definitely should check your script and the permissions on the parentfolder in which average/ is to be created.
您绝对应该检查您的脚本以及要在其中创建 average/的父文件夹的权限。
If it's not just a permissions problem, as the error message suggests, you'll need a Python expert.
如果这不仅仅是权限问题,如错误消息所示,您将需要 Python 专家。

