免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 10246 | 回复: 14
打印 上一主题 下一主题

打开页面的时候不是页面而是下载hello.cgi,为什么? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-10 17:50 |只看该作者 |倒序浏览
我在linux下装了各boa web服务器,用boa提供的cgi-test.cgi示例放在cgi-bin下,在浏览器端可以正常访问网页,但我用c语言写的一个hello.c,通过gcc hello.c -o hello.cgi后,在浏览器端访问hello.cgi,它不是显示页面,而是跳出文件下载窗口,问要不要保存hello.cgi文件,真搞不懂,为什么会这样啊,在网上也没查到相关信息,有哪位牛人指点一下啊,谢谢啦!

论坛徽章:
0
2 [报告]
发表于 2008-09-10 18:00 |只看该作者
1.检查下cgi-bin的配置,是否添加了cgi的后缀

2.C程序里有没有打印content-type信息
printf("Content-type:text/html\n\n");
在输出之前打印

论坛徽章:
0
3 [报告]
发表于 2008-09-10 18:53 |只看该作者
第二条添加了,第一条,如果没有添加cgi后缀,那boa自带的示例cgi-test.cgi怎么可以打开。

论坛徽章:
0
4 [报告]
发表于 2008-09-10 19:21 |只看该作者
Apache没有解析到.cgi,很简单。

论坛徽章:
0
5 [报告]
发表于 2008-09-10 19:21 |只看该作者
配置一下就好了。

论坛徽章:
0
6 [报告]
发表于 2008-09-10 20:06 |只看该作者
我用的不是apache,是boa,而且配置我参考了很多配置,都差不多,就有一次,我修改了int main(void)中把void去掉,能够成功访问过页面,但后来不知为什么又变成只能下载hello.cgi文件了。

论坛徽章:
0
7 [报告]
发表于 2008-09-10 20:11 |只看该作者
如果没解释到.cgi,那cgi-test.cgi怎么可以访问,差别就是cgi-test.cgi是perl写的,hello.cgi是c写的,我也觉的可能是没解释到,但问题出在哪里呢。

论坛徽章:
0
8 [报告]
发表于 2008-09-11 09:37 |只看该作者
cgi-test.cgi,hello.cgi源码都帖出来看看

boa我没试过,apache熟点

论坛徽章:
0
9 [报告]
发表于 2008-09-11 10:39 |只看该作者
[root@localhost cgi-bin]# vim cgi-test.cgi
#! /usr/bin/perl

# Remember that CGI programs have to close out the HTTP header
# (with a pair of newlines), after giving the Content-type:
# and any other relevant or available header information.

# Unlike CGI programs running under Apache, CGI programs under Boa
# should understand some simple HTTP options.  The header (and the
# double-newline) should not be printed if the incoming request was
# in HTTP/0.9.  Also, we should stop after the header if
# REQUEST_METHOD == "HEAD".  Under Apache, nph- programs also have
# to worry about such stuff.

# Feb 3, 2000 -- updated to support POST, and avoid passing
# Malicious HTML Tags as described in CERT's CA-2000-02 advisory.

if ($ENV{"SERVER_PROTOCOL"} ne "HTTP/0.9") {
print "Content-type: text/html; charset=ISO-8859-1\r\n\r\n";
}

exit 0 if ($ENV{"REQUEST_METHOD"} eq "HEAD");

print "<html><head><title>Boa CGI test</title></head><body>\n";
print "<H2>Boa CGI test</H2>\n\n";

$now=`date`;
chomp($now);

print "Date: $now\n";
print "<p>\n";

print "Method: $ENV{\"REQUEST_METHOD\"}\n";
print "<p>\n";

print "<table border=1>\n";
print "<tr><td>Basic GET Form:<br>";
print " <form method=\"get\">\n\
  <input type=\"text\" name=\"parameter_1\" size=5 maxlength=5>\
    <select name=\"select_1\">\
"cgi-test.cgi" 120L, 3314C                                                                                                  1,1          椤剁?
      <option>foo</option>\
      <option>bar</option>\
    </select>\
  <input type=\"submit\" NAME=SUBMIT VALUE=\"Submit\">\
</form>";
print "</td>";
print "<td>Basic POST Form:<br>";
print "<form method=\"post\">\n\
  <input type=\"text\" name=\"parameter_1\" size=5 maxlength=5>\
    <select name=\"select_1\">\
      <option>foo</option>\
      <option>bar</option>\
    </select>\
  <input type=\"submit\" NAME=SUBMIT VALUE=\"Submit\">\
  </form>";
print "</td>";
print "</tr>\n";
print "<tr><td colspan=2>Sample ISINDEX form:<br>\n";
print "<a href=\"$ENV{\"SCRIPT_NAME\"}?param1+param2+param3\">$ENV{\"SCRIPT_NAME\"}?param1+param2+param3</a>\n";
print "</td></tr>";
print "</table>\n";

print "<p>Query String: $ENV{\"QUERY_STRING\"}\n";

# arguments list
print "<p>\nArguments:\n<ol>\n";
if ($#ARGV >= 0) {
       while ($a=shift(@ARGV)) {
        $a=~s/&/&amp;/g;
        $a=~s/</&lt;/g;
        $a=~s/>/&gt;/g;
        print "<li>$a\n";
       }
}
print "</ol>\n";

# environment list
print "<P>\nEnvironment:\n<UL>\n";
foreach $i (keys %ENV) {
        $a=$ENV{$i};
        $a=~s/&/&amp;/g;
        $a=~s/</&lt;/g;
        $a=~s/>/&gt;/g;
        $i=~s/&/&amp;/g;
        $i=~s/</&lt;/g;
        $i=~s/>/&gt;/g;
        print "<li>$i = $a\n";
}
print "</UL>\n";

if ($ENV{REQUEST_METHOD} eq "POST") {
    print "Input stream:<br><hr><pre>\n";
    while (<stdin>) {
        s/&/&amp;/g;
        s/</&lt;/g;
        s/>/&gt;/g;
        print "$_";
    }
    print "</pre><hr>\n";
} else {
    print "No input stream: (not POST)<p>";
}

print "id: ", `id`, "\n<p>\n";

if ($ENV{"QUERY_STRING"}=~/ident/ && $ENV{"REMOTE_PORT"} ne "") {

# Uses idlookup-1.2 from Peter Eriksson  <pen@lysator.liu.se>
# ftp://coast.cs.purdue.edu/pub/to ... idlookup-1.2.tar.gz
# Could use modification to timeout and trap stderr messages
        $a="idlookup ".
           $ENV{"REMOTE_ADDR"}." ".$ENV{"REMOTE_PORT"}." ".$ENV{"SERVER_PORT"};
        $b=qx/$a/;
        print "ident output:<br><pre>\n$b</pre>\n";
}

print "\n<EM>Boa http server</EM>\n";
print "</body></html>\n";

exit 0;

论坛徽章:
0
10 [报告]
发表于 2008-09-11 10:40 |只看该作者
#include <stdlib.h>

int main(void)
{
        printf("Content-Type: test/html\r\n\r\n");
        printf("<html>\n");
//      printf("<head><title>CGI Output</title></head>\n");
        printf("<body><pre>\n");
        printf("hello,world\n");
        printf("</body>\n");
        printf("</html>\n");
//"body"
//"h1The c cgi hello /h1"
//"p"
//"hello %s world!"
//"/p"
//"/body"
//"/html",s
        return 0;
}
~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP