2016-11-17 159 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未記錄文件未找到錯誤 –