如何在IIS中部署Flask应用程序?

时间:2022-12-01 07:11:41

Can anyone help me get a Flask application running on IIS 6? I have tried to use isapi-wsgi, but when I visit the Virtual Directory address I get a page that says "The specified module could not be found." Are there other options for this?

有人能帮我拿一个在IIS 6上运行的Flask应用程序吗?我尝试使用isapi-wsgi,但是当我访问虚拟目录地址时,我得到了一个页面,上面写着“无法找到指定的模块”。还有别的选择吗?

Below is the Python script I wrote for isapi-wsgi. The Virtual Directory was made and everything looked ok in IIS Manager, but the site did not work.

下面是我为isapi-wsgi编写的Python脚本。在IIS管理器中创建了虚拟目录,一切看起来都没问题,但是站点没有工作。

from wof import app
import os

app.secret_key=os.urandom(24)

import isapi_wsgi
def __ExtensionFactory__():
    return isapi_wsgi.ISAPISimpleHandler(app)

if __name__ == '__main__':
    from isapi.install import *
    params = ISAPIParameters()
    sm = [ScriptMapParams(Extension="*", Flags=0)]
    vd = VirtualDirParameters(Name="WOFPy_Sondes", Description="ISAPI-WSGI for WOFPY Sondes test", ScriptMaps=sm, ScriptMapUpdate="replace")
    params.VirtualDirs = [vd]
    HandleCommandLine(params)

3 个解决方案

#1


45  

High Level Overview

HTTP -> IIS -> ISAPI -> FastCGI -> WSGI (Flask application)

HTTP -> IIS -> ISAPI -> FastCGI -> WSGI (Flask应用程序)


Setup Steps

Step 1: Install Required Binaries

  1. Install Python (2.7 or 3.x -- I used 3.3)
  2. 安装Python(2.7或3)。x——我用了3。3)
  3. Install pip-Win (I used version 1.6)
  4. 安装pip-Win(我使用了1.6版)
  5. Install pywin32 (I used version 218)
  6. 安装pywin32(我使用了218版本)
  7. Install the IIS FastCGI extension with fcgisetup 1.5
  8. 安装IIS FastCGI扩展与fcgisetup 1.5。

Step 2: Install Optional Binary Packages

I installed pyodbc using the installer .exe from this site. Installing from source (e.g. pip, for installing into a virtual environment) requires a C/C++ compiler.

我使用安装程序.exe安装了pyodbc。从源代码安装(例如,安装到虚拟环境中)需要一个C/ c++编译器。

Step 3: Get a Copy of wfastcgi.py

Choose a version that will work for you, preferably one that supports Python 3.3 (I used David Ebbo's). You may want the "official" version from here.

选择一个适合您的版本,最好是支持Python 3.3的版本(我使用了David Ebbo的)。您可能需要这里的“官方”版本。

Install the wfastcgi.py script into C:\Inetpub\wwwroot and make sure the account that will serve your application ("Network Service" by default) has read access to it.

安装wfastcgi。py脚本到C:\Inetpub\wwwroot,并确保为您的应用程序服务的帐户(默认为“网络服务”)已经读取了访问权限。

Step 4: Install virtualenv Into the System site-packages

C:\Python33\Scripts\pip.exe install virtualenv

(if you are using Python 3.3 and installed everything in the default location)

(如果您使用的是Python 3.3,并将所有内容安装在默认位置)

Step 5: Install Your Flask Application

  • You may install the application just about anywhere on the system. You may want to install it under C:\Inetpub. For this tutorial, we'll call the root folder of your application install %APPROOT%. (Don't put quotation marks in the environment variable.)

    您可以在系统的任何地方安装应用程序。你可能想在C:\Inetpub下安装它。在本教程中,我们将调用应用程序的根文件夹%APPROOT%。(不要在环境变量中添加引号。)

  • Make sure that the account that will serve your application ("Network Service" by default) has read access to all of the script files. This command:

    确保为您的应用程序服务的帐户(默认为“网络服务”)已读取对所有脚本文件的访问权限。这个命令:

    cacls "%APPROOT%" /S:"D:PAI(A;OICI;FA;;;BA)(A;OICIIO;FA;;;CO)(A;OICI;0x1200a9;;;NS)(A;OICI;FA;;;SY)"
    

    will give your application directory the following permissions:

    将给您的应用程序目录以下权限:

    • BUILTIN\Administrators: Full control of this folder, subfolders, and files
    • 构建\管理员:完全控制这个文件夹、子文件夹和文件。
    • CREATOR OWNER: Full control for subfolders and files only
    • 创建者所有者:仅对子文件夹和文件进行完全控制。
    • NT AUTHORITY\NETWORK SERVICE: Read permissions for this folder, subfolders, and files
    • NT权限\网络服务:读取此文件夹、子文件夹和文件的权限。
    • NT AUTHORITY\SYSTEM: Full control of this folder, subfolders, and files
    • NT权限\系统:对该文件夹、子文件夹和文件的完全控制。
  • Add any local configuration necessary (my application uses a local.cnf file that is ignored by the version control system) -- e.g. database URLs.

    添加任何必要的本地配置(我的应用程序使用的是版本控制系统忽略的local.cnf文件)——例如数据库url。

  • Make sure your application contains a Web.config file in %APPROOT% -- see the section below for information on the file format.

    确保您的应用程序包含一个Web。%APPROOT%的配置文件——请参阅下面的部分以获取关于文件格式的信息。

Step 6: Create a virtualenv For Your Application

C:\Python33\Scripts\virtualenv.exe --system-site-packages "%APPROOT%\env"

(Pick a name other than env if your application already uses that directory.)

(如果您的应用程序已经使用了该目录,请选择其他名称,而不是env。)

Step 7: Install The Packages Required By Your Application to the virtualenv

cd "%APPROOT%"
env\Scripts\activate
pip install -r Packages

(My project keeps the requirements spec in a file named Packages.)

(我的项目在一个名为Packages的文件中保存了需求规范。)

Step 8: Create a Web Site Or Virtual Directory For Your Application

Use inetmgr.msc (Start -> Run…, then enter inetmgr in the edit box and press ENTER) to launch Internet Information Services (IIS) Manager. Make sure to set the local path for the node (Web Site or Virtual Directory) you create to the root folder of your Flask application. wfastcgi.py uses the local path to identify the Flask application to handle the requests.

使用inetmgr。msc(开始->运行…,然后在编辑框中输入inetmgr并按enter)启动Internet Information Services (IIS)管理器。确保将创建的节点(Web站点或虚拟目录)的本地路径设置为Flask应用程序的根文件夹。wfastcgi。py使用本地路径来识别Flask应用程序来处理请求。

Give both Read and Script (Run Scripts) permissions for the node.

为节点提供读取和脚本(运行脚本)权限。

Step 9: Configure fcgiext.ini

This file is located in the same directory as the fcgiext.dll installed in Step 1 (by default, %SYSTEMROOT%\system32\inetsrv).

该文件位于fcgiext的同一目录中。在步骤1中安装的dll(默认情况下,%SYSTEMROOT%\system32\inetsrv)。

In configuring this file, you need several parameters:

在配置这个文件时,您需要几个参数:

  • {site id}: the numeric Site ID you can find in the detail (right-hand) pane of Internet Information Services (IIS) Manager when “Web Sites” is selected from the tree on the left side of the window.
  • {site id}:当从窗口左侧的树中选择“Web站点”时,您可以在Internet Information Services (IIS)管理器的detail(右侧)窗格中找到数字站点id。
  • {application name}: the name of the section within fcgiext.ini that provides the parameters for the FastCGI (ISAPI) handler. You choose this value -- select something that represents your application.
  • {应用程序名称}:fcgiext中部分的名称。为FastCGI (ISAPI)处理程序提供参数的ini。选择这个值——选择表示应用程序的东西。
  • {path to app}: for a Virtual Directory, the URL path within the Web Site to the Virtual Directory to be handled.
  • {path to app}:对于虚拟目录,Web站点内的URL路径到要处理的虚拟目录。
  • {approot}: the path to the root directory of your application.
  • {approot}:通往应用程序根目录的路径。

Use those parameters to:

使用这些参数:

  • Map the FastCGI requests to a handling section:

    将FastCGI请求映射到处理部分:

    • For a whole Web Site, add *:{site id}={application name} to the [Types] section.
    • 对于整个Web站点,在[类型]部分中添加*:{Site id}={应用程序名称}。
    • For a Virtual Directory, add *:/lm/w3svc/{site id}/root/{path to app}={application name} to the [Types] section.
    • 对于虚拟目录,添加*:/lm/w3svc/{site id}/根/{path到app}={应用程序名称}到[类型]部分。
  • Add a handling section ([{application name}]) with parameters for this application (full reference):

    添加一个处理部分([{application name}]),参数为该应用程序(完整引用):

    • ExePath={approot}\env\python.exe
    • ExePath = { approot } \ env \ python.exe
    • Arguments=C:\Inetpub\wwwroot\wfastcgi.py (or wherever the wfastcgi.py adapter script is installed)
    • 参数= C:\ Inetpub \ wwwroot \ wfastcgi。py(或任何wfastcgi。安装了py适配器脚本)
    • EnvironmentVars=ENV_VAR1:value,ENV_VAR2:value,etc. (see the full reference for quoting rules). This is a good place to set your WSGI_LOG environment variable -- make sure the account serving the site (“Network Service” by default) has write permissions for the file and (if the file doesn’t exist) permission to add a file to the containing directory.
    • EnvironmentVars = ENV_VAR1:价值,ENV_VAR2:价值等。(请参阅引用规则的完整参考)。这是设置WSGI_LOG环境变量的好地方——确保为站点服务的帐户(默认为“网络服务”)对文件有写权限,并且(如果文件不存在)允许将文件添加到包含的目录中。

Step 10: Configure FastCGI Handling for the Target URLs

Using Internet Information Services (IIS) Manager, select “Properties...” from the context (right-click) menu of the node (Web Site or Virtual Directory) to be served by your Flask application and:

使用Internet Information Services (IIS)管理器,选择“属性……”“由您的烧瓶应用程序提供的节点(网站或虚拟目录)的上下文(右键单击)菜单,并:

  • In the “Home Directory” tab (Web Site) or “Virtual Directory” tab (Virtual Directory), click the “Configuration..." button.

    在“主目录”选项卡(Web站点)或“虚拟目录”选项卡(虚拟目录)中,单击“配置…”按钮。

  • In the “Wildcard application maps” section, use the “Insert..." button to add a wildcard mapping:

    在“通配符应用程序映射”部分中,使用“Insert…”按钮添加通配符映射:

    • The executable is the FastCGI extension DLL installed in Step 1. Its default location is %SYSTEMROOT%\system32\inetsrv\fcgiext.dll.
    • 可执行文件是安装在步骤1中的FastCGI扩展DLL。它的默认位置是%SYSTEMROOT%\system32\inetsrv\fcgiext.dll。
    • Make sure “Verify that file exists” is unchecked. Flask applications do their own routing that doesn’t necessarily have anything to do with the files on the disk.
    • 确保“验证该文件存在”是未检查的。Flask应用程序可以自己进行路由,这并不一定与磁盘上的文件有任何关系。

Web.config

This file is (in this setup) read by wfastcgi.py, not by IIS.

这个文件(在这个设置中)由wfastcgi读取。py,而不是IIS。

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
    <applicationSettings>
        <add key=“PYTHONPATH” value=“”/>
        <add key=“WSGI_HANDLER” value=“module.application”/>
    </applicationSettings>
</configuration>
  • <add> elements add environment variables (os.environ in Python).

    元素添加环境变量(操作系统)。环绕在Python中)。

  • WSGI_HANDLER must be specified -- it tells wfastcgi.py how to locate the WSGI application object. If the value ends in "()", wfastcgi.py will call the named object, expecting it to return a WSGI application object.

    必须指定WSGI_HANDLER——它告诉wfastcgi。py如何定位WSGI应用程序对象。如果值以“()”结束,wfastcgi。py将调用命名对象,期望它返回一个WSGI应用程序对象。

  • PYTHONPATH is handled specially -- wfastcgi.py performs (environment) variable expansion (using the Windows standard %VAR% notation) on the value of PYTHONPATH, then splits the result at semicolons and appends the entries to sys.path before invoking the WSGI application. Because wfastcgi.py changes the current directory to the path specified as the local path of the Web Site or Virtual Directory before importing the module containing the WSGI application object, including an empty string in the PYTHONPATH will cause the search to include your Flask application directory as a starting point. You can also set PYTHONPATH in fcgiext.ini (in which case it is included in sys.path by the interpreter and then again by wfastcgi.py).

    PYTHONPATH是专门处理的——wfastcgi。py执行(环境)变量扩展(使用Windows标准%VAR%符号)对PYTHONPATH的值进行处理,然后将结果拆分为分号,并将条目附加到sys中。调用WSGI应用程序之前的路径。因为wfastcgi。py将当前目录更改为Web站点或虚拟目录的本地路径指定的路径,然后导入包含WSGI应用程序对象的模块,其中包括在PYTHONPATH中的空字符串,将使搜索包含您的Flask应用程序目录作为起始点。您还可以在fcgiext中设置PYTHONPATH。ini(在这种情况下,它包含在sys中)。通过翻译的路径,然后再通过wfastcgi.py。

  • WSGI_RESTART_FILE_REGEX gives a Python regular expression used to filter file-change notifications for paths that should trigger FastCGI handler process restarts. Set this to trigger when source files or configuration files change. I use (?i).*\.(py|cnf|config)$.

    WSGI_RESTART_FILE_REGEX提供了一个Python正则表达式,用于筛选应该触发FastCGI处理程序重新启动的路径的文件更改通知。当源文件或配置文件发生更改时,将此设置为触发器。我用(?我)。* \。(py | cnf |配置)美元。

  • WSGI_LOG may be set here, but I think it is better set in fcgiext.ini.

    可以在这里设置WSGI_LOG,但是我认为在fcgiext.ini中设置更好。


For IIS 7

Some things with FastCGI changed dramatically with IIS 7. Beginning with this version, FastCGI has support directly through IIS and is not configured through an extension (i.e. Step 1.4 is not necessary and fcgiext.ini does not control FastCGI behavior for IIS 7+ and there is no need to create/edit it). Instead, make sure that CGI is enable under Internet Information Services in Control Panel > Programs and Features > Turn Windows Features on or off.

在iis7中,一些使用FastCGI的东西发生了戏剧性的变化。从这个版本开始,FastCGI直接通过IIS支持,而不是通过扩展(也就是步骤1.4不是必需的和fcgiext)配置的。ini不控制IIS 7+的FastCGI行为,也不需要创建/编辑它。相反,要确保CGI在控制面板>程序的互联网信息服务下启用,并且在>的功能上打开或关闭。

Web.config

IIS 7 is the first version of IIS to read configuration settings related to FastCGI from the Web.config file. Your Web.config file will need to contain, within the <configuration> element, a <system.webServer> element containing a <handlers> element containing an <add> element with the attributes:

IIS 7是第一个从Web上读取与FastCGI相关的配置设置的IIS版本。配置文件。你的网络。配置文件需要包含在 元素,一个 <系统中。webserver> 元素包含了一个包含 <添加> 元素和属性的>元素的 <处理程序> 元素:

  • path: *
  • 路径:*
  • verb: *
  • 动词:*
  • modules: FastCgiModule
  • 模块:FastCgiModule
  • resourceType: Unspecified
  • resourceType:不明
  • requireAccess: Script
  • requireAccess:脚本
  • scriptProcessor: the tricky one
  • scriptProcessor:棘手

The scriptProcessor Attribute

This attribute of the <add> element must contain the full path to the Python interpreter .exe file you want to use (the one in the Scripts subfolder of your Python virtualenv) followed by a | and then the full path to the wfastcgi.py file you are using. As these paths are dependent on the setup of the machine on which your app is running, you may want to have this attribute set as part of your deployment process.

<添加> 元素的这个属性必须包含Python解释器.exe文件的完整路径(在Python virtualenv的脚本子文件夹中),然后是|,然后是wfastcgi的完整路径。您正在使用的py文件。由于这些路径依赖于您的应用程序正在运行的机器的设置,您可能希望将这个属性设置为部署过程的一部分。

IIS Server-wide Set Up

  • In inetmgr, click on the server node in the tree and then choose FastCGI Settings from the center pane. A list of executable/argument pairs will come up.
  • 在inetmgr中,单击树中的服务器节点,然后从中心窗格中选择FastCGI设置。将出现一个可执行/参数对列表。
  • Add an entry for the full paths to your python.exe and the wfastcgi.py you are using. Both should be given the same way they show up in the <handlers>/<add> element in your Web.config.
  • 为您的python添加完整路径的条目。exe和wfastcgi。py您正在使用。两者都应该以相同的方式显示在 / <在web.config中添加> 元素。
  • Make sure to set up the PYTHONPATH environment variable in the new FastCGI application entry to include the root of your application codebase. The advice about adding an empty PYTHONPATH entry in the <applicationSettings> of your Web.config may not apply to this version of IIS.
  • 确保在新的FastCGI应用程序项中设置了PYTHONPATH环境变量,以包含应用程序代码库的根。关于在您的Web的 中添加一个空的pythonpath条目的建议。配置可能不适用于本版本的iis。

#2


3  

Check out Django's page on the subject. It helped me set up a working Django project, but it shouldn't be that different for a Flask app.

查看Django关于这个主题的页面。它帮助我建立了一个工作的Django项目,但是对于一个Flask应用程序来说,它不应该是不同的。

http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer

http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer

#3


0  

I never use IIS, but IIS supports CGI gateway, therefore you should be able to adapt CGI with WSGI.

我从不使用IIS,但IIS支持CGI网关,因此您应该能够适应CGI和WSGI。

IIS <--> CGI <--> WSGI

To run a WSGI as a CGI script, you can use the CGIHandler in Python standard library.

要将WSGI作为CGI脚本运行,您可以在Python标准库中使用CGIHandler。

#1


45  

High Level Overview

HTTP -> IIS -> ISAPI -> FastCGI -> WSGI (Flask application)

HTTP -> IIS -> ISAPI -> FastCGI -> WSGI (Flask应用程序)


Setup Steps

Step 1: Install Required Binaries

  1. Install Python (2.7 or 3.x -- I used 3.3)
  2. 安装Python(2.7或3)。x——我用了3。3)
  3. Install pip-Win (I used version 1.6)
  4. 安装pip-Win(我使用了1.6版)
  5. Install pywin32 (I used version 218)
  6. 安装pywin32(我使用了218版本)
  7. Install the IIS FastCGI extension with fcgisetup 1.5
  8. 安装IIS FastCGI扩展与fcgisetup 1.5。

Step 2: Install Optional Binary Packages

I installed pyodbc using the installer .exe from this site. Installing from source (e.g. pip, for installing into a virtual environment) requires a C/C++ compiler.

我使用安装程序.exe安装了pyodbc。从源代码安装(例如,安装到虚拟环境中)需要一个C/ c++编译器。

Step 3: Get a Copy of wfastcgi.py

Choose a version that will work for you, preferably one that supports Python 3.3 (I used David Ebbo's). You may want the "official" version from here.

选择一个适合您的版本,最好是支持Python 3.3的版本(我使用了David Ebbo的)。您可能需要这里的“官方”版本。

Install the wfastcgi.py script into C:\Inetpub\wwwroot and make sure the account that will serve your application ("Network Service" by default) has read access to it.

安装wfastcgi。py脚本到C:\Inetpub\wwwroot,并确保为您的应用程序服务的帐户(默认为“网络服务”)已经读取了访问权限。

Step 4: Install virtualenv Into the System site-packages

C:\Python33\Scripts\pip.exe install virtualenv

(if you are using Python 3.3 and installed everything in the default location)

(如果您使用的是Python 3.3,并将所有内容安装在默认位置)

Step 5: Install Your Flask Application

  • You may install the application just about anywhere on the system. You may want to install it under C:\Inetpub. For this tutorial, we'll call the root folder of your application install %APPROOT%. (Don't put quotation marks in the environment variable.)

    您可以在系统的任何地方安装应用程序。你可能想在C:\Inetpub下安装它。在本教程中,我们将调用应用程序的根文件夹%APPROOT%。(不要在环境变量中添加引号。)

  • Make sure that the account that will serve your application ("Network Service" by default) has read access to all of the script files. This command:

    确保为您的应用程序服务的帐户(默认为“网络服务”)已读取对所有脚本文件的访问权限。这个命令:

    cacls "%APPROOT%" /S:"D:PAI(A;OICI;FA;;;BA)(A;OICIIO;FA;;;CO)(A;OICI;0x1200a9;;;NS)(A;OICI;FA;;;SY)"
    

    will give your application directory the following permissions:

    将给您的应用程序目录以下权限:

    • BUILTIN\Administrators: Full control of this folder, subfolders, and files
    • 构建\管理员:完全控制这个文件夹、子文件夹和文件。
    • CREATOR OWNER: Full control for subfolders and files only
    • 创建者所有者:仅对子文件夹和文件进行完全控制。
    • NT AUTHORITY\NETWORK SERVICE: Read permissions for this folder, subfolders, and files
    • NT权限\网络服务:读取此文件夹、子文件夹和文件的权限。
    • NT AUTHORITY\SYSTEM: Full control of this folder, subfolders, and files
    • NT权限\系统:对该文件夹、子文件夹和文件的完全控制。
  • Add any local configuration necessary (my application uses a local.cnf file that is ignored by the version control system) -- e.g. database URLs.

    添加任何必要的本地配置(我的应用程序使用的是版本控制系统忽略的local.cnf文件)——例如数据库url。

  • Make sure your application contains a Web.config file in %APPROOT% -- see the section below for information on the file format.

    确保您的应用程序包含一个Web。%APPROOT%的配置文件——请参阅下面的部分以获取关于文件格式的信息。

Step 6: Create a virtualenv For Your Application

C:\Python33\Scripts\virtualenv.exe --system-site-packages "%APPROOT%\env"

(Pick a name other than env if your application already uses that directory.)

(如果您的应用程序已经使用了该目录,请选择其他名称,而不是env。)

Step 7: Install The Packages Required By Your Application to the virtualenv

cd "%APPROOT%"
env\Scripts\activate
pip install -r Packages

(My project keeps the requirements spec in a file named Packages.)

(我的项目在一个名为Packages的文件中保存了需求规范。)

Step 8: Create a Web Site Or Virtual Directory For Your Application

Use inetmgr.msc (Start -> Run…, then enter inetmgr in the edit box and press ENTER) to launch Internet Information Services (IIS) Manager. Make sure to set the local path for the node (Web Site or Virtual Directory) you create to the root folder of your Flask application. wfastcgi.py uses the local path to identify the Flask application to handle the requests.

使用inetmgr。msc(开始->运行…,然后在编辑框中输入inetmgr并按enter)启动Internet Information Services (IIS)管理器。确保将创建的节点(Web站点或虚拟目录)的本地路径设置为Flask应用程序的根文件夹。wfastcgi。py使用本地路径来识别Flask应用程序来处理请求。

Give both Read and Script (Run Scripts) permissions for the node.

为节点提供读取和脚本(运行脚本)权限。

Step 9: Configure fcgiext.ini

This file is located in the same directory as the fcgiext.dll installed in Step 1 (by default, %SYSTEMROOT%\system32\inetsrv).

该文件位于fcgiext的同一目录中。在步骤1中安装的dll(默认情况下,%SYSTEMROOT%\system32\inetsrv)。

In configuring this file, you need several parameters:

在配置这个文件时,您需要几个参数:

  • {site id}: the numeric Site ID you can find in the detail (right-hand) pane of Internet Information Services (IIS) Manager when “Web Sites” is selected from the tree on the left side of the window.
  • {site id}:当从窗口左侧的树中选择“Web站点”时,您可以在Internet Information Services (IIS)管理器的detail(右侧)窗格中找到数字站点id。
  • {application name}: the name of the section within fcgiext.ini that provides the parameters for the FastCGI (ISAPI) handler. You choose this value -- select something that represents your application.
  • {应用程序名称}:fcgiext中部分的名称。为FastCGI (ISAPI)处理程序提供参数的ini。选择这个值——选择表示应用程序的东西。
  • {path to app}: for a Virtual Directory, the URL path within the Web Site to the Virtual Directory to be handled.
  • {path to app}:对于虚拟目录,Web站点内的URL路径到要处理的虚拟目录。
  • {approot}: the path to the root directory of your application.
  • {approot}:通往应用程序根目录的路径。

Use those parameters to:

使用这些参数:

  • Map the FastCGI requests to a handling section:

    将FastCGI请求映射到处理部分:

    • For a whole Web Site, add *:{site id}={application name} to the [Types] section.
    • 对于整个Web站点,在[类型]部分中添加*:{Site id}={应用程序名称}。
    • For a Virtual Directory, add *:/lm/w3svc/{site id}/root/{path to app}={application name} to the [Types] section.
    • 对于虚拟目录,添加*:/lm/w3svc/{site id}/根/{path到app}={应用程序名称}到[类型]部分。
  • Add a handling section ([{application name}]) with parameters for this application (full reference):

    添加一个处理部分([{application name}]),参数为该应用程序(完整引用):

    • ExePath={approot}\env\python.exe
    • ExePath = { approot } \ env \ python.exe
    • Arguments=C:\Inetpub\wwwroot\wfastcgi.py (or wherever the wfastcgi.py adapter script is installed)
    • 参数= C:\ Inetpub \ wwwroot \ wfastcgi。py(或任何wfastcgi。安装了py适配器脚本)
    • EnvironmentVars=ENV_VAR1:value,ENV_VAR2:value,etc. (see the full reference for quoting rules). This is a good place to set your WSGI_LOG environment variable -- make sure the account serving the site (“Network Service” by default) has write permissions for the file and (if the file doesn’t exist) permission to add a file to the containing directory.
    • EnvironmentVars = ENV_VAR1:价值,ENV_VAR2:价值等。(请参阅引用规则的完整参考)。这是设置WSGI_LOG环境变量的好地方——确保为站点服务的帐户(默认为“网络服务”)对文件有写权限,并且(如果文件不存在)允许将文件添加到包含的目录中。

Step 10: Configure FastCGI Handling for the Target URLs

Using Internet Information Services (IIS) Manager, select “Properties...” from the context (right-click) menu of the node (Web Site or Virtual Directory) to be served by your Flask application and:

使用Internet Information Services (IIS)管理器,选择“属性……”“由您的烧瓶应用程序提供的节点(网站或虚拟目录)的上下文(右键单击)菜单,并:

  • In the “Home Directory” tab (Web Site) or “Virtual Directory” tab (Virtual Directory), click the “Configuration..." button.

    在“主目录”选项卡(Web站点)或“虚拟目录”选项卡(虚拟目录)中,单击“配置…”按钮。

  • In the “Wildcard application maps” section, use the “Insert..." button to add a wildcard mapping:

    在“通配符应用程序映射”部分中,使用“Insert…”按钮添加通配符映射:

    • The executable is the FastCGI extension DLL installed in Step 1. Its default location is %SYSTEMROOT%\system32\inetsrv\fcgiext.dll.
    • 可执行文件是安装在步骤1中的FastCGI扩展DLL。它的默认位置是%SYSTEMROOT%\system32\inetsrv\fcgiext.dll。
    • Make sure “Verify that file exists” is unchecked. Flask applications do their own routing that doesn’t necessarily have anything to do with the files on the disk.
    • 确保“验证该文件存在”是未检查的。Flask应用程序可以自己进行路由,这并不一定与磁盘上的文件有任何关系。

Web.config

This file is (in this setup) read by wfastcgi.py, not by IIS.

这个文件(在这个设置中)由wfastcgi读取。py,而不是IIS。

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
    <applicationSettings>
        <add key=“PYTHONPATH” value=“”/>
        <add key=“WSGI_HANDLER” value=“module.application”/>
    </applicationSettings>
</configuration>
  • <add> elements add environment variables (os.environ in Python).

    元素添加环境变量(操作系统)。环绕在Python中)。

  • WSGI_HANDLER must be specified -- it tells wfastcgi.py how to locate the WSGI application object. If the value ends in "()", wfastcgi.py will call the named object, expecting it to return a WSGI application object.

    必须指定WSGI_HANDLER——它告诉wfastcgi。py如何定位WSGI应用程序对象。如果值以“()”结束,wfastcgi。py将调用命名对象,期望它返回一个WSGI应用程序对象。

  • PYTHONPATH is handled specially -- wfastcgi.py performs (environment) variable expansion (using the Windows standard %VAR% notation) on the value of PYTHONPATH, then splits the result at semicolons and appends the entries to sys.path before invoking the WSGI application. Because wfastcgi.py changes the current directory to the path specified as the local path of the Web Site or Virtual Directory before importing the module containing the WSGI application object, including an empty string in the PYTHONPATH will cause the search to include your Flask application directory as a starting point. You can also set PYTHONPATH in fcgiext.ini (in which case it is included in sys.path by the interpreter and then again by wfastcgi.py).

    PYTHONPATH是专门处理的——wfastcgi。py执行(环境)变量扩展(使用Windows标准%VAR%符号)对PYTHONPATH的值进行处理,然后将结果拆分为分号,并将条目附加到sys中。调用WSGI应用程序之前的路径。因为wfastcgi。py将当前目录更改为Web站点或虚拟目录的本地路径指定的路径,然后导入包含WSGI应用程序对象的模块,其中包括在PYTHONPATH中的空字符串,将使搜索包含您的Flask应用程序目录作为起始点。您还可以在fcgiext中设置PYTHONPATH。ini(在这种情况下,它包含在sys中)。通过翻译的路径,然后再通过wfastcgi.py。

  • WSGI_RESTART_FILE_REGEX gives a Python regular expression used to filter file-change notifications for paths that should trigger FastCGI handler process restarts. Set this to trigger when source files or configuration files change. I use (?i).*\.(py|cnf|config)$.

    WSGI_RESTART_FILE_REGEX提供了一个Python正则表达式,用于筛选应该触发FastCGI处理程序重新启动的路径的文件更改通知。当源文件或配置文件发生更改时,将此设置为触发器。我用(?我)。* \。(py | cnf |配置)美元。

  • WSGI_LOG may be set here, but I think it is better set in fcgiext.ini.

    可以在这里设置WSGI_LOG,但是我认为在fcgiext.ini中设置更好。


For IIS 7

Some things with FastCGI changed dramatically with IIS 7. Beginning with this version, FastCGI has support directly through IIS and is not configured through an extension (i.e. Step 1.4 is not necessary and fcgiext.ini does not control FastCGI behavior for IIS 7+ and there is no need to create/edit it). Instead, make sure that CGI is enable under Internet Information Services in Control Panel > Programs and Features > Turn Windows Features on or off.

在iis7中,一些使用FastCGI的东西发生了戏剧性的变化。从这个版本开始,FastCGI直接通过IIS支持,而不是通过扩展(也就是步骤1.4不是必需的和fcgiext)配置的。ini不控制IIS 7+的FastCGI行为,也不需要创建/编辑它。相反,要确保CGI在控制面板>程序的互联网信息服务下启用,并且在>的功能上打开或关闭。

Web.config

IIS 7 is the first version of IIS to read configuration settings related to FastCGI from the Web.config file. Your Web.config file will need to contain, within the <configuration> element, a <system.webServer> element containing a <handlers> element containing an <add> element with the attributes:

IIS 7是第一个从Web上读取与FastCGI相关的配置设置的IIS版本。配置文件。你的网络。配置文件需要包含在 元素,一个 <系统中。webserver> 元素包含了一个包含 <添加> 元素和属性的>元素的 <处理程序> 元素:

  • path: *
  • 路径:*
  • verb: *
  • 动词:*
  • modules: FastCgiModule
  • 模块:FastCgiModule
  • resourceType: Unspecified
  • resourceType:不明
  • requireAccess: Script
  • requireAccess:脚本
  • scriptProcessor: the tricky one
  • scriptProcessor:棘手

The scriptProcessor Attribute

This attribute of the <add> element must contain the full path to the Python interpreter .exe file you want to use (the one in the Scripts subfolder of your Python virtualenv) followed by a | and then the full path to the wfastcgi.py file you are using. As these paths are dependent on the setup of the machine on which your app is running, you may want to have this attribute set as part of your deployment process.

<添加> 元素的这个属性必须包含Python解释器.exe文件的完整路径(在Python virtualenv的脚本子文件夹中),然后是|,然后是wfastcgi的完整路径。您正在使用的py文件。由于这些路径依赖于您的应用程序正在运行的机器的设置,您可能希望将这个属性设置为部署过程的一部分。

IIS Server-wide Set Up

  • In inetmgr, click on the server node in the tree and then choose FastCGI Settings from the center pane. A list of executable/argument pairs will come up.
  • 在inetmgr中,单击树中的服务器节点,然后从中心窗格中选择FastCGI设置。将出现一个可执行/参数对列表。
  • Add an entry for the full paths to your python.exe and the wfastcgi.py you are using. Both should be given the same way they show up in the <handlers>/<add> element in your Web.config.
  • 为您的python添加完整路径的条目。exe和wfastcgi。py您正在使用。两者都应该以相同的方式显示在 / <在web.config中添加> 元素。
  • Make sure to set up the PYTHONPATH environment variable in the new FastCGI application entry to include the root of your application codebase. The advice about adding an empty PYTHONPATH entry in the <applicationSettings> of your Web.config may not apply to this version of IIS.
  • 确保在新的FastCGI应用程序项中设置了PYTHONPATH环境变量,以包含应用程序代码库的根。关于在您的Web的 中添加一个空的pythonpath条目的建议。配置可能不适用于本版本的iis。

#2


3  

Check out Django's page on the subject. It helped me set up a working Django project, but it shouldn't be that different for a Flask app.

查看Django关于这个主题的页面。它帮助我建立了一个工作的Django项目,但是对于一个Flask应用程序来说,它不应该是不同的。

http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer

http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer

#3


0  

I never use IIS, but IIS supports CGI gateway, therefore you should be able to adapt CGI with WSGI.

我从不使用IIS,但IIS支持CGI网关,因此您应该能够适应CGI和WSGI。

IIS <--> CGI <--> WSGI

To run a WSGI as a CGI script, you can use the CGIHandler in Python standard library.

要将WSGI作为CGI脚本运行,您可以在Python标准库中使用CGIHandler。