【问题标题】:perl/cgi script not found error 404 apache2perl/cgi 脚本未找到错误 404 apache2
【发布时间】:2017-03-31 23:21:25
【问题描述】:

我在 /var/cgi-bin 目录中有一个 perl 脚本,它使用 url 正常执行:

localhost/cgi-bin/filename.pl

但是当我通过 html 文件调用同一个文件时,loaclhost 服务器返回 404 not found 错误。

代码: html文件:

<?xml version="1.0"encoding="utf-8"?>
<html>
            <head>
                            <title>light bulbsr form</title>
            </head>
            <body>

<form action="/cgi-bin/bulbs.pl" method="POST">

user name<input type="text" name="myname" size="30"/><br>

select the items:<br>

<input type="checkbox" name="b" value="2.39" /> four100 watt light bulbs  </br>
<input type="checkbox" name="b" value="4.29">  eight 100 watt light bulbs </br>
<input type="checkbox" name="b" value="3.95">  four 100 watt  long life bulbs </br>
<input type="checkbox" name="b" value="7.49"> eight100 watt  long life bulbs </br>

Select the mode of the payment:</br>

<input type ="radio" name="paymode" value="visa" checked="checked"/>Visa<br>
<input type ="radio" name="paymode" value="Master card"/>Master card<br>
<input type ="radio" name="paymode" value="Discover"/>Discover<br>

                            <input type="submit" value="submit order"/>
                            <input type="reset" value="Clear the form"/>
            </body>
</html>

perl 文件:

#!/usr/bin/perl
use CGI qw(:standard);
use strict;


print header(),start_html ("Bill ");
print p("The total cost:0");br();
print end_html;

apache2 000-default.conf:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ScriptAlias /cgi-bin/ /var/cgi-bin/
     <Directory "/var/cgi-bin/">
             AllowOverride None
             Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
             Require all granted
     </Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

【问题讨论】:

  • HTML 文档的 URL 是什么?您可能需要cgi-bin/filename.pl/cgi-bin/filename.pl,因为您的HTML 文件不在cgi-bin 目录中。
  • 我希望这是一个学习练习。你不会用这个来获取信用卡号码吧?
  • 是的,这是一个学习练习。请帮忙!!
  • 你说cgi-bin在/var/cgi-bin。 HMTL 文件在哪里?
  • html文件在/var/www/html

标签: perl apache2 cgi http-status-code-404


【解决方案1】:

您的表单操作是“filename.pl”。这意味着 Web 服务器将在与包含表单的 HTML 页面相同的目录中查找“filename.pl”。这不是它的地方。您可能需要完整路径。

<form action="/cgi-bin/filename.pl">

【讨论】:

  • edit your question 提供更多详细信息。包含此表单的 HTML 页面在哪里?您的 CGI 目录在哪里?您在 Web 服务器错误日志中遇到什么错误?
  • 解决了!问题出在 apache 服务器上。一旦我重新启动系统,您的解决方案就起作用了。谢谢!!
猜你喜欢
  • 1970-01-01
  • 2014-05-31
  • 2011-01-31
  • 2012-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多