Help please set up a bunch of Apache + FastCGI to run Python web applications in the Windows 7 operating system.

Used software:

  • Apache 2.4 web server (C: \ Apache24 \ bin \ httpd.exe);
  • module "mod_fcgid.so" (version 2.3.9) for raising FastCGI in Apache (C: \ Apache24 \ modules \ mod_fcgid.so);
  • Python 2.7.11 (C: \ Apache24 \ bin \ python \ Scripts \ python.exe)
  • operating system Windows 7 Maximum x86.

I have registered the mod_fcgid.so module in "httpd.conf" in this way:

LoadModule fcgid_module "modules/mod_fcgid.so" FcgidInitialEnv PATH "C:/Apache24/bin/python/Scripts;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/Apache24/bin;" FcgidInitialEnv SystemRoot "C:/Windows" FcgidInitialEnv SystemDrive "C:" FcgidInitialEnv TEMP "C:/Windows/Temp" FcgidInitialEnv TMP "C:/Windows/Temp" FcgidInitialEnv windir "C:/WINDOWS" FcgidInitialEnv SERVER_ADDR "127.0.0.1" FcgidInitialEnv SERVER_NAME "localhost" FcgidInitialEnv SERVER_PORT "80" FcgidInitialEnv SERVER_PROTOCOL "HTTP" FcgidInitialEnv REQUEST_METHOD "GET" <IfModule fcgid_module> </IfModule> <Directory "c:/Apache24/fcgi-bin"> AllowOverride None Allow from all Options +ExecCGI AddHandler fcgid-script .fcgi Require all granted </Directory> 

Also added a line:

 ScriptAlias /fcgi/ "c:/Apache24/fcgi-bin/" 

in the section of the file "httpd.conf".

After that, "mod_fcgid.so" appeared in the list of connected Apache modules:

 httpd.exe -M . . . . . negotiation_module (shared) setenvif_module (shared) fcgid_module (shared) 

I installed all the necessary Python modules and wrote the simplest flask application "myapp.py":

 #!C:/Apache24/bin/python/Scripts/python.exe from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run() 

When launched from the console, the application works correctly and sends the string "Hello World!" To the browser at the URL (localhost: 5000). And finally, I created the "run.fcgi" script, which should launch the "myapp.py" application via FastCGI:

 #!C:/Apache24/bin/python/Scripts/python.exe # -*- coding: utf-8 -*- import os from flup.server.fcgi import WSGIServer from myapp import app environ = dict(os.environ.items()) environ['SERVER_ADDR'] = '127.0.0.1' environ['SERVER_PORT'] = '80' environ['SERVER_NAME'] = 'localhost' environ['SERVER_PROTOCOL'] = 'HTTP' environ['REQUEST_METHOD'] = 'GET' if __name__ == '__main__': WSGIServer(app, debug = True, environ=environ).run() 

As a result, when you start Apache and go to the browser at http: //localhost/fcgi/run.fcgi, I get the error: "500 Internal Server Error"

and the following lines appear in the Apache error log:

 [Mon Mar 28 15:00:22.062069 2016] [mpm_winnt:notice] [pid 4020:tid 196] AH00455: Apache/2.4.18 (Win32) mod_fcgid/2.3.9 configured -- resuming normal operations [Mon Mar 28 15:00:22.062069 2016] [mpm_winnt:notice] [pid 4020:tid 196] AH00456: Apache Lounge VC14 Server built: Dec 9 2015 10:17:39 [Mon Mar 28 15:00:22.062069 2016] [core:notice] [pid 4020:tid 196] AH00094: Command line: 'C:\\Apache24\\bin\\httpd.EXE -d C:/Apache24' [Mon Mar 28 15:00:22.082069 2016] [mpm_winnt:notice] [pid 4020:tid 196] AH00418: Parent: Created child process 2832 Apache server interrupted... 016] [mpm_winnt:notice] [pid 2832:tid 220] AH00354: Child: Starting 64 worker threads. [Mon Mar 28 15:00:25.766076 2016] [fcgid:warn] [pid 2832:tid 732] (OS 109) анал был закрыт. : [client ::1:49407] mod_fcgid: get overlap result error [Mon Mar 28 15:00:25.768077 2016] [core:error] [pid 2832:tid 732] [client ::1:49407] End of script output before headers: run.fcgi 

Please tell me what I'm doing wrong, why don't Python scripts run through FastCGI.

    1 answer 1

    Try creating the myapp directory in it __init__.py files and the views.py directory /templates/index.html I described this link
    The problem with the apache or flask It worked for me, but not quite as desired (the essence of the problem is stated). I just run it via CGI, I met on the network ( http://flask.pocoo.org/docs/0.10/deploying/fastcgi/ ) the description and launch via FastCGI, but adding the environment variables was not there environ = dict(os.environ.items())