简体   繁体   中英

Python FastCGI on IIS [Error 500]

I'm having difficulty trying to get FastCGI working on IIS 7 for Python scripts within an existing ASP.NET site setup. I have managed to setup CGI and use it with Python scripts but don't want to incur its overhead for each request. I've also tried HeliconZoo and got WSGI working, but it maps itself to a subdirectory of the site (as an application entry point) whereas I want to be able to have python scripts anywhere in the web tree alongside ASP.NET files.

I've tried adapting the instructions in this post :

Enable CGI as Role Service within IIS
Install Python 2.7
Install WFastCGI 2.0.msi
Create new handler mapping (module mapping): image here .
NB I have tried both with and without the wfastcgi argument above.

After clicking OK it asks if I want to add this to the FastCGI Application settings, so I accept.

Finally I give IIS_IUSRS permission to read/execute files under C:\\Python27 and create a test.py file in wwwroot:

print 'Content-Type: text/plain'
print ''
print 'Hello, world!'

When I navigate to localhost/test.py I get an Error 500, but it is not the IIS 500 error page, it is just white with no info. When I check the IIS event logs there is nothing I can see printing in there.

Any pointers would be appreciated.

I've create an automation which setup django site using wfastcgi. Hope it help

@ECHO OFF
rem Check for IIS setup
IF NOT EXIST %windir%\system32\inetsrv\appcmd.exe (
    ECHO Please have IIS 7.5 install first
    GOTO END
)

rem Default settings
SET CWD=%~dp0
SET PYTHON_EXE=%CWD%env\Scripts\python.exe
SET PROJECT_NAME=myproject
SET SITE_NAME=%PROJECT_NAME%
SET SITE_PHYSIC_PATH=%~dp0
SET SITE_URL=*
SET SITE_PORT=8000
SET SITE_PROTOCOL=http
SET DJANGO_SETTING=%PROJECT_NAME%.settings

rem Gathering information
ECHO IIS 7.5 Django Setup
ECHO Author: James spyjamesbond0072003@gmail.com
ECHO ===========================================
ECHO.

IF NOT EXIST %PYTHON_EXE% (
    SET /p PYTHON_EXE="Enter python.exe path (%PYTHON_EXE%):" %=%
)
SET /p PROJECT_NAME="Enter project name (%PROJECT_NAME%):" %=%
SET SITE_NAME=%PROJECT_NAME%
SET DJANGO_SETTING=%PROJECT_NAME%.settings
SET /p SITE_PHYSIC_PATH="Enter project directory, which contain manage.py (%SITE_PHYSIC_PATH%): " %=%
SET /p DJANGO_SETTING="Django settings module (%DJANGO_SETTING%):" %=%
SET /p SITE_NAME="Enter IIS site name (%PROJECT_NAME%):" %=%
SET /p SITE_PROTOCOL="Enter http|https for protocol (%SITE_PROTOCOL%): " %=%

SET /p SITE_URL="Enter site url (%SITE_URL%):" %=%
IF %SITE_URL%==localhost (
    SET SITE_URL=*
)
SET PYHANDLE=PyFastCGI_%SITE_NAME%

SET /p SITE_PORT="Enter port (%SITE_PORT%):" %=%

SET WFCGI_FILE=%SITE_PHYSIC_PATH%wfastcgi.py
IF NOT EXIST %WFCGI_FILE% (
    SET /p WFCGI_FILE="Please enter full path for wfastcgi.py: " %=%
)

ECHO =====================================
ECHO Installing
ECHO Install FASTCGI for IIS. Please wait.
start /wait %windir%\System32\PkgMgr.exe /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-Security;IIS-RequestFiltering;IIS-HttpCompressionStatic;IIS-WebServerManagementTools;IIS-ManagementConsole;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI;IIS-CGI

ECHO.
ECHO Create IIS Site: %SITE_NAME%
%windir%\system32\inetsrv\appcmd add site /name:%SITE_NAME% /physicalPath:%SITE_PHYSIC_PATH% /bindings:%SITE_PROTOCOL%/%SITE_URL%:%SITE_PORT%:
%windir%\system32\inetsrv\appcmd start site /site.name:%SITE_NAME%

ECHO.
ECHO Setup Python FastCGI Handler
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI "/+[fullPath='%PYTHON_EXE%', arguments='%WFCGI_FILE%']"

ECHO.
ECHO Register the handler for this site
%windir%\system32\inetsrv\appcmd set config "%SITE_NAME%" /section:system.webServer/handlers "/+[name='%PYHANDLE%',path='*',verb='*',modules='FastCgiModule',scriptProcessor='%PYTHON_EXE%|%WFCGI_FILE%',resourceType='Unspecified']" /commit:site

ECHO.
ECHO Configure the handler to run your Django application
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%PYTHON_EXE%', arguments='%WFCGI_FILE%'].environmentVariables.[name='DJANGO_SETTINGS_MODULE',value='%DJANGO_SETTING%']" /commit:apphost

ECHO.
ECHO Configure PYTHONPATH so your Django app can be found by the Python interpreter
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%PYTHON_EXE%', arguments='%WFCGI_FILE%'].environmentVariables.[name='PYTHONPATH',value='%SITE_PHYSIC_PATH%']" /commit:apphost

ECHO.
ECHO Tell the FastCGI to WSGI gateway which WSGI handler to use:
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%PYTHON_EXE%', arguments='%WFCGI_FILE%'].environmentVariables.[name='WSGI_HANDLER',value='django.core.handlers.wsgi.WSGIHandler()']" /commit:apphost

ECHO.
ECHO Restart IIS
iisreset
ECHO Done...
:END

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