uwsgi

1. 安装

pip install uwsgi

2. 配置

👉官方文档

在 django 根项目下创建 uwsgi.ini 文件,写入如下内容

[uwsgi]

# 使用 nginx 连接时使用,Django 程序所在服务器地址
socket = 172.17.0.10:8000

# 项目根目录
chdir = /home/hanjiale/djangoproject

# 项目中 wsgi.py 文件的相对目录
module = DjangoDemo.wsgi

# 启动主进程,来管理其他进程,其它的 uwsgi 进程都是这个 master 进程的子进程,如果 kill 这个 master 进程,相当于 kill 所有的 uwsgi 进程
master = true

# worker 进程数
processes = 2

# 允许用内嵌的语言启动线程。
enable-threads = true

# 存放 master 进程编号的文件,用于停止、启动 uwsgi
pidfile = uwsgi.pid

# 输出日志到 uwsgi.log 文件,使 uwsgi 能够脱离终端
daemonize = uwsgi.log

# 当服务器退出的时候自动删除 unix socket 文件和 pid 文件
vacuum = true

# 串行化 accept,防止“惊群”现象
thunder-lock = true

3. 启动 uwsgi

启动 uwsgi

uwsgi --ini uwsgi.ini

停止 uwsgi。uwsgi.pid 文件中存放的是 master 进程编号。

uwsgi --stop uwsgi.pid

重启 uwsgi

uwsgi --reload uwsgi.pid

4. !!! no internal routing support, rebuild with pcre support !!!

出现这个好像是因为 uwsgi 不支持正则表达式。解决办法 👉参考

pip uninstall uwsgi
sudo apt-get install libpcre3 libpcre3-dev
pip install uwsgi --no-cache-dir

5. uwsgi.log

uwsgi 初始化时的信息如下。可以看到 master 进程编号为 26911,两个 worker 进程分别是 26912 和 26913。

*** Starting uWSGI 2.0.19.1 (64bit) on [Sun Jan  3 17:54:33 2021] ***
compiled with version: 7.5.0 on 02 January 2021 09:36:25
os: Linux-4.15.0-118-generic #119-Ubuntu SMP Tue Sep 8 12:30:01 UTC 2020
nodename: VM-0-10-ubuntu
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/hanjiale/djangoproject
writing pidfile to uwsgi.pid
detected binary path: /home/hanjiale/.virtualenvs/py37/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /home/hanjiale/djangoproject
your processes number limit is 7075
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: enabled
uwsgi socket 0 bound to TCP address 172.17.0.10:8000 fd 3
Python version: 3.7.9 (default, Aug 18 2020, 06:22:45)  [GCC 7.5.0]
Python main interpreter initialized at 0x560a13a71a50
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 218760 bytes (213 KB) for 2 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x560a13a71a50 pid: 26911 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 26911)
spawned uWSGI worker 1 (pid: 26912, cores: 1)
spawned uWSGI worker 2 (pid: 26913, cores: 1)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值