问题
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");
}
compiled it gcc hello.c -o hello.cgi
and placed it in /var/www/mycgi
Afterward I modified httpd.conf to add the following
ScriptAlias /mycgi/ "/var/www/mycgi/"
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>
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!
回答1:
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
then restart apache2 and it will load the cgi.load
file this time.
来源:https://stackoverflow.com/questions/19335987/cgi-wont-run-just-download-on-apache-server