【发布时间】: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