@breakerthb
2016-06-04 10:39
字数 1490
阅读 1387
uWSGI
适用于各种Linux平台。
可以去pypi,搜索uwsgi下载:https://pypi.Python.org/pypi/uWSGI/
安装命令如下:
$ tar xvzf uwsgi-2.0.9.tar.gz
$ cd uwsgi-2.0.9
$ make
这也是django1.7文档里推荐的方式,适合各种Linux平台。
$ sudo pip install uwsgi
注:下图为官网的安装说明截图:
新建test.py文件,内容如下:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return "Hello World"
然后在终端运行:
$ uwsgi --http :8001 --wsgi-file test.py
在浏览器内输入:http://127.0.0.1:8000,看是否有“Hello World”输出,若没有输出,请检查你的安装过程。
ini 格式说明
1,ini配置为 key=value 形式
2,在ini配置文件里,#号为注释,
3,布尔值为 true 和 false
4,在命令行里,uwsgi myconf.ini 等价于 uwsgi --ini myconf.ini
[uwsgi]
socket = 127.0.0.1:8000
workers = 4
1,命令行参数格式:--
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)
其他选项说明:
其他选项,具体可以通过 --help 选项来查看:
$ uwsgi --help
注:下图为官网的 django ini 配置说明截图:
■ 参考:
A,《官方文档》:http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html
B,《uWSGI参考资料》:http://www.cnblogs.com/zhouej/archive/2012/03/25/2379646.html