简体   繁体   中英

Apache does not execute .fcg file

I made the most basic fastcgi program using fastcgipp. I copied it into the /var/www/cgi-bin . I then went to /etc/httpd/conf/httpd.conf .

I replaced:

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

with this:

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options +ExecCGI
    Require all granted

    SetHandler fastcgi-script
</Directory>

But when I go to localhost/cgi-bin/index.fcg , the browser prompts me to download the fcg file instead of executing it.

I am using Fedora 29.

EDIT: This is the httpd.conf

ServerRoot "/etc/httpd"

Listen 127.0.0.1:80

Include conf.modules.d/*.conf

User apache
Group apache

ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/var/www/html"

<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

<Directory "/var/www/html">

    Options Indexes FollowSymLinks

    AllowOverride None

    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

#

<Directory "/var/www/cgi-bin">
    #AllowOverride None
    Options +ExecCGI
    #Require all granted
    Order allow,deny
    Allow from all
    SetHandler fcgid-script
</Directory>

<IfModule mime_module>

    TypesConfig /etc/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on
IncludeOptional conf.d/*.conf

Edit: I somehow get apache to execute the script. But now, the server gives me a 500 internal error. So, I checked the error_log file. It says:

End of script output before headers

I checked my code. I had outputted the header. This is the main.cpp file:

#include <fstream>
#include <boost/date_time/posix_time/posix_time.hpp>

void error_log(const char* msg) {
    static std::ofstream error;

    if(!error.is_open()){
        error.open("/tmp/errlog", std::ios_base::out | std::ios_base::app);
    }

    error << "[" << boost::posix_time::second_clock::local_time() << "]: " << msg << "\n"; 
}

#include <fastcgi++/request.hpp>
#include <fastcgi++/manager.hpp>

class HelloWorld : public Fastcgipp::Request<char> {

    bool response() {
        out << "Content:Type: text/html\r\n\r\n";
        out << "<html><head><meta charset=\"utf-8\"></head><body>";
        out << "<p>It works!!!!</p>";
        out << "</body></html>";

        err << "Hi log!";

        return true;
    }

};

int main() {
    Fastcgipp::Manager<HelloWorld> manager;
    manager.setupSignals();
    manager.listen();
    manager.start();
    manager.join();

    return 0;
}

1) Added SetHandler fcgid-script in the <Directory "/var/www/cgi-bin"> tag in httpd.conf

2) I made a typo in the header. Replaced Content:Type:text/html with Content-Type:text/html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM