I publish a successful, detailed steps are listed below for your reference
condition:
win2012,
IIS7,
python 3.8.1
wfastcgi 3.0.0
false 1.1.1
Fundamental
By configuring the bridge, using the IIS request wfastcgi, startup program developed do flask response frame. Among them, the key point is that website in IIS configuration requires a fastcgi configuration, designated as python.exe cgi program, as specified wfastcgi.py script execution.
That web.config configuration settings to complete the bridge.
wfastcgi 3.0.0
Reads as follows:
https://pypi.org/project/wfastcgi/
Deployment instructions for IIS
https://docs.microsoft.com/zh-cn/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2017
Specific steps:
1. install python on the server, it is recommended not to install to the default directory, and check all users option. Doing so may result in failure due to insufficient privileges to perform.
python points 32, 64-bit versions, this should be consistent with your development side. I installed in the c: \ website \ python38 directory.
2. Install all dependencies python.
I am here is to develop end: pip freeze> requirements.txt generate requirements.txt file. Pip -r requirements.txt server installation.
Server-side pip install wfastcgi installation wfastcgi. Here will find more than a few files at the beginning of the wfastcgi python / scripts directory, where there wfastcgi-enable.
IIS server is installed, choose the fastcgi installation, cgi two expansion packs.
IIS functions to register wfastcgi
According wfastcgi 3.0.0 instructions, you need to enable the function. In fact, the actual increase is a fastCgi IIS settings.
Cmd execute with administrator privileges:
wfastcgi-enable
Screenshot execution results
After execution you can see, it has prompted the configuration of IIS. And gives the configuration parameters: C:\pythons\Python37\python.exe|C:\pythons\Python37\Lib\site-packages\wfastcgi.py
Description: can now be used as a FastCGI script processor
This place is important to understand.
In other words, you can add a new Web site, this site if you want to use wfastcgi flask connected application that can be configured using the above parameters and using IIS has been configured in fastCGI script interpreter.
View Results in IIS Manager:
View the IIS configuration.
FastCGI should add a good program, and if not then the following can not be performed:
fastCGI Configuration
There is no longer any need to configure the so-called arguments, environment and so on. Because it is global, follow-up should be configured in the site.
4.3.3. Add Website
On IIS Manager to add a new Web site (if it is the default site, you can skip).
I added a flaskr site, virtual directory, point to C:\py\flask-tutorial
specify the port number as follows:8001
Most Baidu out of the article, here began to tell how to create a new web.config, best to use IIS Manager to help us create a new, they do not need to do it. Lest error.
Processing Mapper
Add a mapping program modules:
Site Handler Mappings → → Add Module Mapping
Configuration module:
Add Module Mapping
Executable content configuration is 4.3.2 prompts the parameter content: C:\pythons\Python37\python.exe|C:\pythons\Python37\Lib\site-packages\wfastcgi.py
.
Configuration request limited to *
:
Configuration request limit
OK, the system will configure one web.config
into the project directory. what? You then no, it does not matter. A website will publish up after the first execution, we will have a look. At least I have here is this.
Configuration Item
Namely web.config detailed process. Here you can manually, can also be configured in IIS Manager.
Here is the convenience to directly edit the file, not error-prone.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<!-- handlers在4.3.2步骤中配置好,IIS管理器生成,不要手工修改 -->
<handlers>
<add name="flaskr" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\pythons\Python37\python.exe|C:\pythons\Python37\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" />
</handlers>
</system.webServer>
<!-- appSettings节点需要手工添加 -->
<appSettings>
<!-- 2个必须要有的参数:
@WSGI_HANDLER:fastCGI获得请求后调用的flask应用入口。
@PYTHONPATH: 执行整个应用的项目目录
-->
<add key="WSGI_HANDLER" value="flaskr.create_app()" />
<add key="PYTHONPATH" value="C:\py\flask-tutorial" />
<!-- 可选参数, 我这里就配置一个日志文件,其他应该参考 https://pypi.org/project/wfastcgi/ -->
<add key="WSGI_LOG" value="C:\xlog\flaskr_web.log" />
</appSettings>
</configuration>
WSGI_HANDLER Parameter Description
Here it is seriously misleading place. I wasted too much time.
Many examples or documentation Baidu out, and are ***. App. In fact, it is wrong. Finally, according to wfastcgi 3.0.0 as described, it would understand the concept of this parameter: Entrance execution of the program.
As the example of most of the flask are single-file, and simply as follows:
app = Flask(__name__)
Therefore, the configuration here as long as __name__.app
you can, in fact, execute app py file in a variable, and this app
variable is Flask()
the return value of the function only.
I use a modular approach here, in the __init__.py
middle there is a function to create the app. So the configuration value is: flaskr.create_app()
without any management or start py file, you can use. A modular fashion, in fact, more convenient.
Will be deployed on IIS-based Web application framework Flask
xiaoou22 concern appreciates the support
Will be deployed on IIS-based Web application framework Flask
xiaoou22 concern
2019.02.11 21:13:39 number of words read 1,781 1,363
1. Demand
The original system is deployed on IIS, and now need to develop some new features, these new features found easily achieved with a python, and began construction. And between the old functionality using http communication naturally convenient. So to find a small frame, select flask as a Web framework Python. Therefore, it is best able to python deployed on IIS.
2. Environment
Service program | version | operating system |
---|---|---|
IIS | 10.0 | Windows10 |
IIS | 8.0 | Windows Server 2012 |
Python3 | 3.7.* | Windows 10, Windows Server 2012 |
wfastcgi | 3.0.0 | - |
Flask | 1.0 | - |
3. Technical principles cited
According to the article Baidu, basically not reliable. Technically still need to research their own original look.
3.1 Rationale
By configuring the bridge, using the IIS request wfastcgi, startup program developed do flask response frame. Among them, the key point is that website in IIS configuration requires a fastcgi configuration, designated as python.exe cgi program, as specified wfastcgi.py script execution.
That web.config configuration settings to complete the bridge.
wfastcgi 3.0.0
Reads as follows:
https://pypi.org/project/wfastcgi/
Deployment instructions for IIS
https://docs.microsoft.com/zh-cn/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2017
3.2. Key
Because IIS is a Microsoft product, it is necessary to go to Microsoft's documentation to find information. fastcgi bridge script, is actually Microsoft's own development. The web is so popular python, the current Microsoft should have a corresponding method to deal with.
4. combat
4.1. Installation Python3
After repeated tests, if the windows security Python3, be sure to install a custom directory, and check all users option.
A time to start testing, breath next to go, in any case not easy to use, always being given fastcgi error or 500, then reinstall Python, and specify the directory and open the only solution. It should be fastcgi configuration requires execute permissions caused.
Download:
https://www.python.org/downloads/release/python-372/
find an executable file downloads. Deploy end of 32bit or 64 bit version and you should be consistent with the development side. After testing, it was found that part of the package there is an incompatibility.
I am here to install C:\pythons\Python37
the next, convenient handling, file permissions windows10 also avoid the problem. The default is the installation directory to users of appData, a lot of trouble.
4.2. The mounting assembly
4.2.1 Online server
After the development version itself can be made setup.py
, there should be reference: https://dormousehole.readthedocs.io/en/latest/tutorial/install.html ,
the dependencies are placed:
install_requires=[
'flask',
'pandas',
],
Then form their own whl, after copied to the server, the install their whl
pip install flaskr.whl
pip install program requires configuration according to the corresponding components.
4.2.2. Offline deployment
Offline lot of trouble. Venv you need to download the packages are good whl, followed pip. Other methods are less reliable.
Then of course also be made disposable offline installation requirement. But the need to pay attention to the order of each package, or otherwise fail to install. Specific special record it later.
4.3. Configuration
After installing the deployment, should form an executive directory. Here, I used the application flaskr case that is a little flask of the blog.
Tutorial Original: https://dormousehole.readthedocs.io/en/latest/tutorial/index.html
This tutorial application is a Web form factory, rather than to other articles Baidu in a simple helloword, this is more practical. Because this case did not start the application app.py.
On Baidu Ye Hao, other Microsoft documents, we are all focused on the interpretation of the contents of web.config, this is very misleading deployment. Here is configured using a visual interface. (CentOS really enjoyed it and so is the deployment of R & D can execute scripts, windows or better visualization)
4.3.1. Directory environment
content | table of Contents |
---|---|
python.exe | C: \ pythons \ Python37 \ python.exe |
wfastcgi.py | C:\pythons\Python37\Lib\site-packages\wfastcgi.py |
flaskr project | C:\py\flask-tutorial |
Internal directory structure of the project
C:\py\flask-tutorial
├── flaskr/
│ ├── __init__.py
│ ├── db.py
│ ├── schema.sql
│ ├── auth.py
│ ├── blog.py
│ ├── templates/
│ │ ├── base.html
│ │ ├── auth/
│ │ │ ├── login.html
│ │ │ └── register.html
│ │ └── blog/
│ │ ├── create.html
│ │ ├── index.html
│ │ └── update.html
│ └── static/
│ └── style.css
The project directory without any py file, the project directly flaskr package
4.3.2. Registration wfastcgi functionality to IIS
According wfastcgi 3.0.0 instructions, you need to enable the function. In fact, the actual increase is a fastCgi IIS settings.
Cmd execute with administrator privileges:
wfastcgi-enable
Screenshot execution results
After execution you can see, it has prompted the configuration of IIS. And gives the configuration parameters: C:\pythons\Python37\python.exe|C:\pythons\Python37\Lib\site-packages\wfastcgi.py
Description: can now be used as a FastCGI script processor
This place is important to understand.
In other words, you can add a new Web site, this site if you want to use wfastcgi flask connected application that can be configured using the above parameters and using IIS has been configured in fastCGI script interpreter.
View Results in IIS Manager:
View the IIS configuration.
FastCGI should add a good program, and if not then the following can not be performed:
fastCGI Configuration
There is no longer any need to configure the so-called arguments, environment and so on. Because it is global, follow-up should be configured in the site.
4.3.3. Add Website
On IIS Manager to add a new Web site (if it is the default site, you can skip).
I added a flaskr site, virtual directory, point to C:\py\flask-tutorial
specify the port number as follows:8001
Most Baidu out of the article, here began to tell how to create a new web.config, best to use IIS Manager to help us create a new, they do not need to do it. Lest error.
Processing Mapper
Add a mapping program modules:
Site Handler Mappings → → Add Module Mapping
Configuration module:
Add Module Mapping
Executable content configuration is 4.3.2 prompts the parameter content: C:\pythons\Python37\python.exe|C:\pythons\Python37\Lib\site-packages\wfastcgi.py
.
Configuration request limited to *
:
Configuration request limit
OK, the system will configure one web.config
into the project directory.
4.3.4. Configuration Item
Namely web.config detailed process. Here you can manually, can also be configured in IIS Manager.
Here is the convenience to directly edit the file, not error-prone.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<!-- handlers在4.3.2步骤中配置好,IIS管理器生成,不要手工修改 -->
<handlers>
<add name="flaskr" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\pythons\Python37\python.exe|C:\pythons\Python37\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" />
</handlers>
</system.webServer>
<!-- appSettings节点需要手工添加 -->
<appSettings>
<!-- 2个必须要有的参数:
@WSGI_HANDLER:fastCGI获得请求后调用的flask应用入口。
@PYTHONPATH: 执行整个应用的项目目录
-->
<add key="WSGI_HANDLER" value="flaskr.create_app()" />
<add key="PYTHONPATH" value="C:\py\flask-tutorial" />
<!-- 可选参数, 我这里就配置一个日志文件,其他应该参考 https://pypi.org/project/wfastcgi/ -->
<add key="WSGI_LOG" value="C:\xlog\flaskr_web.log" />
</appSettings>
</configuration>
WSGI_HANDLER Parameter Description
Here it is seriously misleading place. I wasted too much time.
Many examples or documentation Baidu out, and are ***. App. In fact, it is wrong. Finally, according to wfastcgi 3.0.0 as described, it would understand the concept of this parameter: Entrance execution of the program.
As the example of most of the flask are single-file, and simply as follows:
app = Flask(__name__)
Therefore, the configuration here as long as __name__.app
you can, in fact, execute app py file in a variable, and this app
variable is Flask()
the return value of the function only.
I use a modular approach here, in the __init__.py
middle there is a function to create the app. So the configuration value is: flaskr.create_app()
without any management or start py file, you can use. A modular fashion, in fact, more convenient.
5. Summary
Baidu out of the various articles, it is a failure, it is misleading, it is a waste of time .
Some people say there is no windows + IIS deployment flask more trouble. The key is that we are not clear 3.0.0 wfastcgi instructions. Read and understand the original concept is very important. English is not good, you can also refer to the Visual Studio Help documentation .
Several aspects are misguided:
- webinstall tool - can not use the offline deployment
- cgi installation, this is actually the normal needs of the IIS configuration
- url redirection, this does not need. 2 Microsoft documents are not mentioned, I do not have to configure that the successful deployment
- Web.config, as long as the configuration can then wfastcgi-enable, any arbitrary distribution, chaotic environment parameter set is useless. web.config site only need to configure the parameters, go to the description.
- Static file: After testing, it seems that there is no need special configuration.
After venv content deployment project development, wfastcgi directly configured venv, it seems to have no effect. Without success. Honestly allocation of production environment for the global environment now.
Reference: https://www.jianshu.com/p/8b6b263144ba