Nginx + Uwsgi + flask centos 部署服务
时间: 2023-07-14 07:13:06 浏览: 203
以下是在 CentOS 上部署 Flask 应用程序的基本步骤:
1. 安装 Nginx 和 Uwsgi
```bash
sudo yum install nginx uwsgi-plugin-python3
```
2. 创建 Flask 应用程序
```python
# app.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello, World!"
if __name__ == "__main__":
app.run()
```
3. 创建 Uwsgi 配置文件
```ini
# uwsgi.ini
[uwsgi]
module = app:app
master = true
processes = 5
socket = 127.0.0.1:5000
chmod-socket = 666
vacuum = true
die-on-term = true
```
4. 启动 Uwsgi
```bash
uwsgi --ini uwsgi.ini
```
5. 创建 Nginx 配置文件
```nginx
# /etc/nginx/conf.d/flask.conf
server {
listen 80;
server_name example.com;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:5000;
}
}
```
6. 启动 Nginx
```bash
sudo systemctl start nginx
```
7. 配置防火墙以允许 HTTP 流量
```bash
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload
```
现在您的 Flask 应用程序应该已经准备好在 CentOS 上部署了!
阅读全文