gunicorn

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__).resolve
  • 18
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值