How to deploy a FastAPI web app on IIS server?

Viewed 3072

I have a FastAPI web app that I'm trying to deploy on IIS version 10.0.* on Windows server 2019.

Right now, I can run the application locally with no issues, you can find the repository here: https://github.com/shaybarak11/Twitter-API

What I'm doing in order to run it locally is running the application via the CMD:
python main.py

And in the main.py file, I have this line of code that start the app:

uvicorn.run("main:app", host="0.0.0.0", port=8000, log_level="info")

So now, I'm trying to deploy this app on IIS. These are the steps I took so far:

  1. downloaded IIS on the Windows server.
  2. hit add website on IIS Manager page.
  3. added the Physical path of the project directory.
  4. connected as the Administrator.
  5. Went to Handler Mappings and added the python interpreter.
  6. Following the guide of configuring the web.config file for python app, I get now HTTP error 500.19 - that indicates the problem is with my web.config file.

My web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="C:\Users\Administrator\AppData\Local\Programs\Python\Python39\python.exe"
                  arguments="C:\Users\Administrator\Desktop\Twitter-API\main.py"
                  stdoutLogEnabled="true"
          stdoutLogFile="c:\home\LogFiles\python.log"
                  startupTimeLimit="60"
                  processesPerApplication="16">
      <environmentVariables>
        <environmentVariable name="USERNAME" value="root" />
    <environmentVariable name="PASSWORD" value="password" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>

Does someone have any idea what the error is?

Many thanks,
Shay.

0 Answers
Related