首页 技术 正文
技术 2022年11月21日
0 收藏 843 点赞 2,198 浏览 1652 个字

安装uwsgi
# pip install uwsgi

配置uwsgi:
首先要明确的是,如果你喜欢用命令行的方式(如shell)敲命令,那可以省去任何配置。
但是,绝大多数人,还是不愿意记那么长的命令,反复敲的。所以uwsgi里,就给大家提供了多种配置,省去你启动时候,需要敲一长串命令的过程。
uwsgi 有多种配置可用:
1,ini ,
2,xml ,
3,json,
4,yaml。

从uwsgi的官方文档来看,貌似(我个人的理解)推荐用ini方式,所以下面的配置也都是基于ini的。

● ini 格式说明:
1,ini配置为 key=value 形式
2,在ini配置文件里,#号为注释,
3,布尔值为 true 和 false
4,在命令行里,uwsgi myconf.ini 等价于 uwsgi –ini myconf.ini

● uwsgi.ini 配置示例:
[uwsgi]
socket = 127.0.0.1:8000
workers = 4

uwsgi 选项说明:
● 选项的格式:
1,命令行参数格式:–<option>
2,配置格式(以ini为例):option = xxxx

● 常用选项:
socket : 地址和端口号,例如:socket = 127.0.0.1:50000
processes : 开启的进程数量
workers : 开启的进程数量,等同于processes(官网的说法是spawn the specified number ofworkers / processes)
chdir : 指定运行目录(chdir to specified directory before apps loading)
wsgi-file : 载入wsgi-file(load .wsgi file)
stats : 在指定的地址上,开启状态服务(enable the stats server on the specified address)
threads : 运行线程。由于GIL的存在,我觉得这个真心没啥用。(run each worker in prethreaded mode with the specified number of threads)
master : 允许主进程存在(enable master process)
daemonize : 使进程在后台运行,并将日志打到指定的日志文件或者udp服务器(daemonize uWSGI)。实际上最常用的,还是把运行记录输出到一个本地文件上。
pidfile : 指定pid文件的位置,记录主进程的pid号。
vacuum : 当服务器退出的时候自动清理环境,删除unix socket文件和pid文件(try to remove all of the generated file/sockets)
disable-logging : 不记录请求信息的日志。只记录错误以及uWSGI内部消息到日志中。如果不开启这项,那么你的日志中会大量出现这种记录:
[pid: 347|app: 0|req: 106/367] 117.116.122.172 () {52 vars in 961 bytes} [Thu Jul 7 19:20:56 2016] POST /post => generated 65 bytes in 6 msecs (HTTP/1.1 200) 2 headers in 88 bytes (1 switches on core 0)

● 其他选项说明:
其他选项,具体可以通过 –help 选项来查看:
uwsgi –help

项目中的配置文件
[root@6c2879a830ce run]# cat /tmp/uwsgi.ini
[uwsgi]
http-socket = :80
plugin = python
chdir = /code/run/cms
wsgi-file = cms/wsgi.py
processes = 4
threads = 4
max-request = 20480
log-x-forwarded-for = true
logto = /code/uwsgi_web.log
stats = 127.0.0.1:9191

文章参考链接:
http://blog.csdn.net/chenggong2dm/article/details/43937433

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,050
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,533
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,384
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,160
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,795
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,875