问题描述
我写了一个cgi脚本来处理由另一个程序生成的数据.问题在于此文件位于cgi-bin之外.如何确保我的perl脚本可以读取此文件?我已经尝试过更改此文件的权限,并且还尝试在cgi-bin文件夹中建立链接,但是Apache对此不太聪明.我猜可能的解决方法是:
I've written a cgi script that processes data that is generated by another program. The problem is that this file is located outside the cgi-bin. How can I make sure that my perl scripts can read this file? I've already tried changing the permissions of this file and I also tried to make a link in the cgi-bin folder but Apache is too smart for that. I guess possible solutions are:
- 编辑Apache配置文件,使Apache可以读取cgi-bin之外的文件.
- 使用便携式"网络服务器运行cgi脚本.就像您可以使用python(python -m http.server [port])一样.不幸的是,这不会执行perl cgi脚本.
我很难解决其中一种解决方案.
I'm kind of stuck how to do either one of the solutions.
推荐答案
我已经通过结合使用PSGI和plackup解决了这个问题.
I've solved this problem by using plackup in combination of PSGI.
use CGI::Emulate::PSGI;
use CGI::Compile;
my $sub = CGI::Compile->compile("location/to/script.cgi");
my $app = CGI::Emulate::PSGI->handler($sub);
如果运行plackup file.psgi,它将设置一个以当前用户身份运行的本地Web服务器.问题解决了.
If you run plackup file.psgi, it sets up a local webserver that runs as the current user. Problem solved.
这篇关于如何读取cgi-bin文件夹之外的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!