【问题标题】:Can't get apache to execute perl CGI script无法让 apache 执行 perl CGI 脚本
【发布时间】:2023-04-04 10:51:01
【问题描述】:

编辑:这个问题被错误地标记为How can I troubleshoot my Perl CGI script? 的副本,该问题涉及如何调试 perl 程序,答案解释了如何做到这一点。在这种情况下,我什至没有做到这一点,问题竟然是一个 apache 配置问题,我在 Directory 指令中使用了相对路径,这些东西都没有在该问题的答案中提及.

原问题: 我已经建立了一个 ubuntu 测试服务器(16.04.2 LTS)并试图让 apache 在它上面执行一个 perl cgi 脚本。它从命令行运行良好,但在浏览器中它总是显示源代码。我在这个网站和其他网站上浏览了很多页面的建议,但我无法让它发挥作用,所以任何帮助都将不胜感激。

我网站的 conf 文件如下所示(我希望能够在每个目录的基础上执行脚本):

<VirtualHost *:443>
    DocumentRoot "/var/www/test"
    ServerName mydomain.org
    <Directory "/var/www/test">
            allow from all
            Options None
            Require all granted
    </Directory>

    SSLEngine on
    SSLCertificateFile /etc/webmin/letsencrypt-cert.pem
    SSLCertificateKeyFile /etc/webmin/letsencrypt-key.pem
    SSLCACertificateFile /etc/webmin/letsencrypt-ca.pem

    <Directory "path/to/dir">
            Options ExecCGI Indexes
            AddHandler cgi-script .pl
    </Directory>
</VirtualHost>

我启用 mods 的目录如下所示:

access_compat.load  autoindex.conf  mime.conf         setenvif.load
alias.conf          autoindex.load  mime.load         socache_shmcb.load
alias.load          cgi.load        mpm_prefork.conf  ssl.conf
auth_basic.load     deflate.conf    mpm_prefork.load  ssl.load
authn_core.load     deflate.load    negotiation.conf  status.conf
authn_file.load     dir.conf        negotiation.load  status.load
authz_core.load     dir.load        php7.0.conf
authz_host.load     env.load        php7.0.load
authz_user.load     filter.load     setenvif.conf

error.log 中没有错误,访问日志告诉我:

mydomain.org:443 xx.xxx.xxx.xx - - [27/Apr/2017:10:37:02 +0100] "GET /path/to/dir/test.pl HTTP/1.1" 304 3921 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"

脚本 (test.pl) 就是这样,可以从命令行运行:

#!/usr/bin/perl

print "Content-type: text/html\n\n";

print "Hello, world!\n";

谁能告诉我我在这里做错了什么?

【问题讨论】:

  • 我看到的第一件事:"path/to/dir" 应该是绝对路径:"/path/to/dir" 不应该吗?另外,您的.pl 脚本是否可以通过正确的#! 行执行?
  • 你的明星!使绝对路径有效!澄清一下,有没有办法指定相对于 DocumentRoot 的路径?
  • 我认为Location: 是你想要的。您也可以使用.htaccess 文件。它们适用于它们所在的目录。和/或者你可以使用Files指令来使用文件扩展名来执行。
  • @cbmckay:我认为你应该把它写下来作为答案。

标签: apache perl cgi


【解决方案1】:

如果指令中没有非动态内容,只需添加 ScriptAlias 指令:

ScriptAlias /program_dir/ "/full/path/to/dir/"

【讨论】:

    猜你喜欢
    • 2021-02-20
    • 2018-02-08
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多