The guide you followed, though captured quite a few screen shots and contained a lot of information, does not describe the recommended approach from Microsoft, because Python via FastCGI on IIS is no longer supported as quoted from here,
We recommend using HttpPlatform to configure your apps, as the WFastCGI project is no longer maintained.
To get up-to-date information on this setup, you can refer to my blog post. I list the key points below to make a standalone answer.
Preparation
Prepare a folder such as C:\flask-test
, and create app.py
as
from flask import Flask
def create_app():
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
return app
and wsgi.py
from app import create_app
application = create_app()
Then install both flask
and waitress
,
pip install flask waitress
And test that both flask run
and waitress-serve
work,
PS C:\flask-test> ~\AppData\Local\Programs\Python\Python310\python.exe -m flask run
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
PS C:\flask-test> ~\AppData\Local\Programs\Python\Python310\python.exe -m waitress --port 9000 wsgi:application
INFO:waitress:Serving on http://0.0.0.0:9000
IIS Integration
Add a web.config
file in this folder to enable HttpPlatformHandler,
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\python.log" startupTimeLimit="20" processPath="C:\Users\lextudio\AppData\Local\Programs\Python\Python310\python.exe" arguments="-m waitress --port %HTTP_PLATFORM_PORT% wsgi:application">
</httpPlatform>
</system.webServer>
</configuration>
Then on IIS you can create a new site to point to C:\flask-test
.
More details can be found in my blog post, especially on troubleshooting.