1

我很难在现有的 ASP.NET 站点设置中让 FastCGI 在 IIS 7 上运行 Python 脚本。我已经设法设置 CGI 并将其与 Python 脚本一起使用,但不想为每个请求产生开销。我也尝试过 HeliconZoo 并让 WSGI 工作,但它会将自身映射到站点的子目录(作为应用程序入口点),而我希望能够在 ASP.NET 文件旁边的 Web 树中的任何位置拥有 python 脚本。

我已经尝试调整这篇文章中的说明:

在 IIS 中启用 CGI 作为角色服务
安装 Python 2.7
安装WFastCGI 2.0.msi
创建新的处理程序映射(模块映射):图像在这里
注意我已经尝试过使用和不使用上面的 wfastcgi 参数。

单击确定后,它会询问我是否要将其添加到 FastCGI 应用程序设置中,因此我接受。

最后,我授予 IIS_IUSRS 读取/执行 C:\Python27 下文件的权限,并在 wwwroot 中创建一个 test.py 文件:

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

当我导航到 localhost/test.py 时,我收到错误 500,但它不是 IIS 500 错误页面,它只是白色的,没有任何信息。当我检查 IIS 事件日志时,我看不到任何打印内容。

任何指针将不胜感激。

4

1 回答 1

0

我创建了一个使用 wfastcgi 设置 django 站点的自动化。希望有帮助

@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
于 2014-10-22T03:44:24.677 回答