Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
# Install CGI and ISAPI extension feature
PS C:\Users\Administrator> Install-WindowsFeature Web-CGI,Web-ISAPI-Ext
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Application Development, CGI, ISAPI Exten...
# restart IIS
PS C:\Users\Administrator> Restart-Service W3SVC
PS C:\Users\Administrator> Get-Website
Name ID State Physical Path Bindings
---- -- ----- ------------- --------
Default Web Site 1 Started %SystemDrive%\inetpub\wwwroot http *:80:
RX-7.srv.world 2 Started C:\inetpub\newsite http *:80:RX-7.srv.world
https *:443:rx-7.srv.world sslFlags=0
PS C:\Users\Administrator> Get-ChildItem C:\inetpub\newsite
Directory: C:\inetpub\newsite
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 9/11/2019 7:09 PM content01
d----- 9/11/2019 7:09 PM content02
-a---- 9/9/2019 1:27 AM 28 index.html
# add Python to ISAPI/CGI extension
PS C:\Users\Administrator> Add-WebConfiguration -Filter '/system.webServer/security/isapiCgiRestriction' -Value @{description="Python";path="C:\Program Files\Python37\python.exe %s %s";allowed="true"}
# for example, set [*.py] scripts as executable under [content01] folder on [RX-7.srv.world] site
PS C:\Users\Administrator> Set-WebConfigurationProperty -Filter '/system.webServer/handlers' -Location "RX-7.srv.world/content01" -Name accessPolicy -Value "Read, Script"
PS C:\Users\Administrator> Add-WebConfiguration -Filter '/system.webServer/handlers' -Location "RX-7.srv.world/content01" -Value @{name="Python Interpreter";path="*.py";verb="*";modules="CgiModule";scriptProcessor="C:\Program Files\Python37\python.exe %s %s";resourceType="File"}
# restart Web site
PS C:\Users\Administrator> Restart-WebItem -PSPath 'IIS:\Sites\RX-7.srv.world'
# create test script
PS C:\Users\Administrator> $str_document = @'
print("Content-type: text/html\n\n")
print("Python Script Test Page on IIS")
'@
PS C:\Users\Administrator> Write-Output $str_document | Out-File C:\inetpub\newsite\content01\test.py -Encoding Default
# verify to access
PS C:\Users\Administrator> curl.exe https://rx-7.srv.world/content01/test.py
Python Script Test Page on IIS
|