CGI不会仅在Apache服务器上下载运行 [英] CGI won't run just download on Apache server

查看:188
本文介绍了CGI不会仅在Apache服务器上下载运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对CGI和Apache完全陌生,但是我正在尝试一些事情.首先,我用C语言编写了一个简单的hello CGI.

I'm completly new to CGI and Apache but I'm trying out a few things. To start I wrote a simple hello CGI in C.

#include <stdio.h>

void main() {
    printf("Content-type: text/html\n\n");
    printf("<html>\n");
    printf("<head><title>CGI Output</title></head>\n");
    printf("<body>\n");
    printf("<h1>Hello, world.</h1>\n") ;
    printf("</body>\n");
    printf("</html>\n"); 
}

编译它gcc hello.c -o hello.cgi并将其放在/var/www/mycgi

compiled it gcc hello.c -o hello.cgi and placed it in /var/www/mycgi

此后,我修改了httpd.conf以添加以下内容

Afterward I modified httpd.conf to add the following

ScriptAlias /mycgi/ "/var/www/mycgi/"

在IfModule alias_module和

in the IfModule alias_module and

<Directory "/var/www/mycgi">
    Options +ExecCGI
    AddHandler cgi-script .cgi
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

然后我重新启动了Apache,当我转到localhost/mycgi/hello.cgi时,浏览器只是下载文件而不是运行文件.帮助将不胜感激!

I have then restarted Apache and when I go to localhost/mycgi/hello.cgi the browser just downloads the file instead of running it. Help will be greatly apreciated!

推荐答案

根据 janos 的建议,您应该确保apache2已加载了cgi_module:LoadModule cgi_module modules/mod_cgi.so .您可以通过以下方式做到这一点:

According to janos's advice, you should make sure apache2 has loaded the cgi_module: LoadModule cgi_module modules/mod_cgi.so. You can do this by:

sudo ln -s /etc/apache2/mods-available/cgi.load /etc/apache2/mods-enabled/cgi.load

然后重新启动apache2,这次它将加载cgi.load文件.

then restart apache2 and it will load the cgi.load file this time.

这篇关于CGI不会仅在Apache服务器上下载运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆