2016-11-17 172 views
0

我在/ var/cgi-bin目录有一个perl脚本的URL将正常执行:的Perl/CGI脚本找不到错误404的Apache2

本地主机/ cgi-bin目录/ filename.pl

但当我通过html文件调用相同的文件时,loaclhost服务器返回404未找到的错误。

代码: 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 [email protected] 
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> 
+0

什么是HTML文档的URL?您可能需要'cgi-bin/filename.pl'或'/ cgi-bin/filename.pl',因为您的HTML文件不在'cgi-bin'目录中。 – simbabque

+1

我希望这是一个学习练习。你不会拿这个信用卡号码,是吗? – simbabque

+0

是的,这是一个学习练习。 Plz帮助! –

回答

0

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

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

仍然显示相同的404错误 –

+0

请[编辑您的问题](http://stackoverflow.com/posts/40654525/edit)以包含更多详细信息。包含此表单的HTML页面在哪里?你的CGI目录在哪里?您在Web服务器错误日志中遇到什么错误? –

+0

error.log未记录文件未找到错误 –