我创建了一个使用 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