How to deploy ASGI on IIS?

Shay Barak 1 Reputation point
2021-08-08T11:23:50.587+00:00

Hi everyone,

I have an api server written in FastAPI framework(python) and I would like to
know how to deploy it with IIS on Windows server 2019.
In order to run it locally, the application uses uvicorn(ASGI server).
So basically what I want to know is how to deploy ASGI server on top of IIS,
because right now I'm just running the app via CMD, which is definitely not a good idea at all.
Every time the server for some is going down and then up, I have to restart the app and this is
something that I would like to be automatically.
I looked up for some tutorials on the Internet but I couldn't find one for FastAPI.

Does someone know how to do so?

Many thanks, Shay.

Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,471 questions
Internet Information Services
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 31,826 Reputation points
    2021-08-08T15:17:48.413+00:00

    Disclaimer: I do not know anything about FastAPI framework(python) or uvicorn(ASGI server).

    I do have experience with using IIS as a front end for Tomcat. This involved installing an ISAPI filter into IIS (listening on HTTP and HTTPS) and configuring it to do port forwarding to whatever port we had Tomcat listening on. Client<-->IIS<-->Tomcat<-->WhateverDatabaseItUsed

    I don't know if that's what you mean by "deploy ASGI server on top of IIS". You might have better luck asking this question in an ASGI forum or searching their documentation for ISAPI filters.

    Maybe this? https://github.com/mjkillough/iis-asgi-handler

    If you just want to run a program at system startup, you can use the Windows task scheduler or a tool like NSSM that runs command line programs as a service.

    https://nssm.cc/


  2. Lex Li (Microsoft) 4,742 Reputation points Microsoft Employee
    2024-04-03T00:53:50.4266667+00:00

    The steps to host FastAPI web apps on IIS are straight forward if you use HttpPlatformHandler,

    https://docs.lextudio.com/blog/running-fastapi-web-apps-on-iis-with-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\<user name>\AppData\Local\Programs\Python\Python310\python.exe" arguments="-m uvicorn --port %HTTP_PLATFORM_PORT% main:app">
            </httpPlatform>
        </system.webServer>
    </configuration>