cgi脚本没有执行

发布于 2024-12-05 11:01:33 字数 806 浏览 6 评论 0原文

我有一个 perl.cgi 文件,其内容如下:

#!/usr/bin/perl 
print "Content-type: text/html\n\n";
print "<h1>Hello World</h1>\n";

我使其可执行。 (chmod a+x perl.cgi)

然后我在同一目录中创建了一个新文件 perl.htm。其中包含以下数据:

Content-type: text/html
<p><a href="perl.cgi">RUN perl.cgi</a></p>

当我在浏览器中运行 perl.htm 时,我得到的输出为:

Content-type: text/html
RUN perl.cgi

当我单击 RUN perl.cgi 时,会打开另一个页面并在那里输出是:

#!/usr/bin/perl 
print "Content-type: text/html\n\n";
print "<h1>Hello World</h1>\n";

perl.cgi 没有执行。仅显示文件内容。

编辑:从答案和评论中我知道我必须配置我的网络服务器(apache)来运行cgi脚本。我怎样才能做到这一点?让我知道。

I have a perl.cgi file which has the content:

#!/usr/bin/perl 
print "Content-type: text/html\n\n";
print "<h1>Hello World</h1>\n";

I made it executable. (chmod a+x perl.cgi)

Then I created a new file perl.htm in the same directory. Which has the following data:

Content-type: text/html
<p><a href="perl.cgi">RUN perl.cgi</a></p>

When I run the perl.htm in my browser then I get the output as:

Content-type: text/html
RUN perl.cgi

When I click on RUN perl.cgi another page opens and there the output is:

#!/usr/bin/perl 
print "Content-type: text/html\n\n";
print "<h1>Hello World</h1>\n";

i.e. the perl.cgi is not executing. Only the file contents are being shown.

EDIT: From the answers and comments I came to know that I will have to configure my web server (apache) to run cgi scripts. How can I do that? Let me know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

裂开嘴轻声笑有多痛 2024-12-12 11:01:33

听起来 Apache 没有配置为运行 *.cgi 文件:

AddHandler cgi-script cgi pl
<Directory /path/to/cgi/files>
    Options +ExecCGI
</Directory>

Sounds like Apache is not configured to run *.cgi files:

AddHandler cgi-script cgi pl
<Directory /path/to/cgi/files>
    Options +ExecCGI
</Directory>
木緿 2024-12-12 11:01:33

确保您正在 httpd.conf 文件中加载 CGI 模块:

LoadModule cgi_module module/mod_cgi.so
LoadModule cgi_module module/mod_cgid.so 取决于您运行的 Apache 版本。

您还可以阅读有关其他解决方案的信息
使用 CGI 的动态内容

Make sure you are loading the CGI module in the httpd.conf file:

LoadModule cgi_module modules/mod_cgi.so or
LoadModule cgi_module modules/mod_cgid.so depending on which version of Apache you are running.

You can also read about additional solutions for
Dynamic Content with CGI.

满身野味 2024-12-12 11:01:33

问题已经解决了。我根本没有使用 httpd 服务,而是从 file:// URL 打开。

Perl 脚本未以 HTML 形式执行

Problem has been solved. I was not using httpd service at all, was opening from file:// URL.

Perl script is not executing in HTML form

苏辞 2024-12-12 11:01:33

您需要设置 Web 服务器,以便它执行 *.cgi 文件(或者更常见的是,执行特定目录中的所有文件),而不是像执行 .html 文件那样将它们传送到浏览器。

如何完成此操作取决于您的服务器。

You need to setup your web server so that it executes *.cgi files (or, more normally, all the files in a particular directory) rather than just delivering them to the browser as it does .html files.

How this is done depends on your server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文