1、gunicorn是什么
Gunicorn是一个 Python 的 WSGI HTTP 服务器。它所在的位置通常是在反向代理(如 Nginx)和一个 web 应用(如django)之间,支持eventlet也支持greenlet。
Gunicorn启动项目之后一定会有一个主进程Master和一个或者多个工作进程。工作进程的数量可以指定。工作进程是实际处理请求的进程。主进程维护服务器的运行。
2、gunicorn的作用
1、提高并发
2、帮助负载均衡
3、gunicorn使用
1.下载
# gunicorn是python库
pip install gunicorn
2.常用命令
gunicorn安装后,可以在命令行使用gunicorn的相关命令,gunicorn -h 可以看到全部命令参数和对应注释(英文)。命令及配置后边会用到,配置的内容有很多,参考Gunicorn-配置详解。可以查看gunicorn官网
gunicorn -h # 查看gunicorn的命令参数
gunicorn -v # gunicorn的版本
3.gunicorn快速启动
gunicorn -h # 查看gunicorn的命令参数
gunicorn -v # gunicorn的版本
cd django项目目录(目录包含manage.py和projectname目录)
gunicorn -w 4 -b 127.0.0.1:8000 projectname.wsgi:application
4、gunicorn根据配置文件启动
在yml文件中的启动命令
# && 表示前面的命令执行成功后,后面的命令才能开始执行
# /usr/local/python3/bin/gunicorn -c server/gunicorn_portal.py 表示用gunicorn启动时 用 gunicorn_portal.py 配置文件
# -c 表示 指定配置文件
# server.asgi 表示 server下面的asgi.py文件
cd /app/server/ && /usr/local/python3/bin/gunicorn -c server/gunicorn_portal.py server.asgi
gunicorn_portal.py 配置文件
import os
import multiprocessing
from pathlib import Path
# 指定工作程序的基础路径
BASE_DIR = Path(__file__

最低0.47元/天 解锁文章
4463

被折叠的 条评论
为什么被折叠?



