【问题标题】:Making a perl script executable via a web page通过网页使 perl 脚本可执行
【发布时间】:2021-06-18 13:50:55
【问题描述】:

我正在尝试制作一个带有可通过网页执行的参数的 Perl 脚本。有人可以帮助我开始使用 apache 及其配置吗?我已经尝试了多个小时,但似乎没有任何效果。我正在使用 Apache 2.4.29

【问题讨论】:

  • 您在几个小时内尝试了哪些步骤?
  • 也许这个问题对stackoverflow.com/q/8994348/1741542有帮助
  • 所以我试图让它转到“localhost/cgi-bin/first.pl”,但我不断收到 apache 错误,现在它告诉我 403 Forbidden
  • 要缩小 403 错误的原因,请查看 Apache 的日志文件:/var/log/apache2/access.log 和 /var/log/apache2/error.log。

标签: apache perl


【解决方案1】:

仍然使用 perl 来解决这个问题的一个选项是在服务器的 localhost 中创建一个小型 TCP 服务,您可以在其中发送参数,然后您只需在 apache 中配置一个反向代理到该端口。

例子:

use strict;
use warnings;
use IO::Socket;  
  
my $port = 9999;  

my $server_socket = IO::Socket::INET->new(
     LocalPort => $port,
     Listen    => SOMAXCONN,
     Proto     => 'tcp',
     Reuse     => 1)
     or die "Cannot open socket: $!";
         

print "Server listening on port $port\n";  
  
while ( my $client_socket = $server_socket->accept() ) {
    my $client_host = $client_socket->sockhost();
    run_your_stuff();
    $client_socket->close();
}

   
sub run_your_stuff{
    print "Executing something...\n";
    system("ping google.es");
    # system("perl your_oder_script.pl");
}

【讨论】:

    猜你喜欢
    • 2014-12-16
    • 2019-01-24
    • 2015-10-30
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 2016-04-10
    • 2019-07-01
    • 1970-01-01
    相关资源
    最近更新 更多