【问题标题】:How to run Windows IIS on top of an ASGI server like hypercorn or uvicorn?如何在像 hypercorn 或 uvicorn 这样的 ASGI 服务器上运行 Windows IIS?
【发布时间】:2020-05-20 17:38:19
【问题描述】:

我有一个使用FastApi 用python 编写的基于api 的Web 应用程序,它使用UvicornHypercorn 进行部署。它们都是基于ASGI 的服务器。有没有办法在此之上运行 IIS?

【问题讨论】:

标签: python iis uvicorn asgi hypercorn


【解决方案1】:

您绝对可以通过 IIS 运行。这是您有两种可能的选择(我使用 Hypercorn):

  1. HTTPPlaformHandler

    <configuration>
        <system.webServer>
         <rewrite>
                <rules>
                    <rule name="HTTPS force" enabled="true" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTPS}" pattern="^OFF$" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
                    </rule>
                </rules>
            </rewrite>
            <handlers>
                <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
            </handlers>
            <httpPlatform requestTimeout="00:05:00" startupTimeLimit="120" startupRetryCount="3" stdoutLogEnabled="true" stdoutLogFile=".\logs\python-stdout" processPath="[PATH TO YOUR PYTHON EXE]" arguments="-m hypercorn app.main:app -b 127.0.0.1:%HTTP_PLATFORM_PORT% --keep-alive 5 --worker-class asyncio --workers 9">
                <environmentVariables>
                    <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
                </environmentVariables>
            </httpPlatform>
        </system.webServer>
    </configuration>
    
  2. AspNetCoreModuleV2(如果你使用这个,你必须有一个 config.py 才能正确绑定 URL 和端口。)

     <system.webServer>
       <handlers>
         <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
       </handlers>
       <aspNetCore processPath="[PATH TO PYTHON EXE]" arguments="-m hypercorn app.main:app --config file:config.py" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" requestTimeout="00:26:00" /></system.webServer>   </location><system.webServer></system.webServer> </configuration>
    

【讨论】:

  • 请分享 config.py 文件
猜你喜欢
  • 2021-11-02
  • 2021-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多