nginx部署flask
Flask is a popular python web framework that is most commonly known for creating REST APIs very easily. They are usually deployed using WSGI servers such as Gunicorn or uWSGI.
Flask是一种流行的python Web框架,因非常容易创建REST API而闻名。 它们通常使用WSGI服务器(例如Gunicorn或uWSGI)进行部署。
Another server solution that is much easier to work with and more versatile is NGINX Unit and that’s what we will be looking at here.
Nginx Unit是另一个更易于使用且功能更广泛的服务器解决方案,这就是我们在这里要介绍的内容。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/4994c4690421aeee7056a8f3db45dd23.png)
NGINX Unit is a dynamic application server. It is not to be confused with the popular NGINX web server, although they work great together.
NGINX Unit是一个动态应用服务器。 尽管它们可以很好地协同工作,但不要与流行的NGINX Web服务器混淆。
The great thing about Unit is that it supports a RESTful JSON API. That way you can deploy configuration changes without service disruptions and Unit even runs apps built with multiple languages and frameworks!
Unit的优点在于它支持RESTful JSON API。 这样,您可以部署配置更改而不会中断服务,并且Unit甚至可以运行使用多种语言和框架构建的应用程序!
We will be deploying a very basic flask app and will use the basic hello world template. Create a file named app.py
in your project directory. Here all we’re doing is importing the flask module and creating a simple message for the root route.
我们将部署一个非常基本的flask应用程序,并将使用基本的hello world模板。 在您的项目目录中创建一个名为app.py
的文件。 在这里,我们要做的就是导入flask模块并为根路由创建一条简单消息。
from flask import Flask
app = Flask(__name__)
application = app
@app.route('/')
def hello_world():
return 'Hello, World!'
Next, create a file named requirements.txt
. This will contain details of the dependencies we have and since flas