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.