nginx+uwsgi部署python应用


uwsgi 配置

其实nginx+python+django的配置主要是uwsgi的配置。这里直接贴出我的uwsgi.ini的配置。各个参数具体参看uwsgi文档。

[uwsgi]
#socket = 127.0.0.1:8000 
socket = /tmp/uwsgi.sock
master = true
chdir = /home/lovedboy/myproject/ # django工程目录
wsgi-file = /home/lovedboy/myproject/myapp/wsgi.py
processes = 2
listen = 15000
enable-threads = true
daemonize = /home/lovedboy/uwsgi/uwsgi.log
pidfile = /home/lovedboy/uwsgi/uwsgi.pid
pythonpath = /home/lovedboy/myproject/
buffer-size =  32768
reload-mercy = 8
vacuum = true
max-requests = 20000
socket-timeout = 20
harakiri = 20
memory-report = true

配置完成后,直接用如下命令启动:

sudo uwsgi --ini uwsgi.ini

如果启动成功, tail 一下uwsgi.log 会有类似如下的日志:

*** Starting uWSGI 1.9.11 (32bit) on [Tue Dec 24 19:05:44 2013] ***
compiled with version: 4.7.2 on 29 May 2013 19:25:05
os: Linux-3.5.0-25-generic #39-Ubuntu SMP Mon Feb 25 19:02:34 UTC 2013
nodename: lovedboy 
machine: i686
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /home/lovedboy/uwsgi
detected binary path: /usr/local/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your processes number limit is 31974
your memory page size is 4096 bytes
detected max file descriptor number: 65536
lock engine: pthread robust mutexes
uwsgi socket 0 inherited UNIX address /tmp/uwsgi.sock fd 3
Python version: 2.7.3 (default, Apr 10 2013, 05:13:00)  [GCC 4.7.2]
Python main interpreter initialized at 0x9fa20f8
python threads support enabled
your server socket listen backlog is limited to 10000 connections
your mercy for graceful operations on workers is 60 seconds
mapped 277932 bytes (271 KB) for 2 cores
*** Operational MODE: preforking ***
added /home/lovedboy/myproject/ to pythonpath.
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x9fa20f8 pid: 30509 (default app)
*** uWSGI is running in multiple interpreter mode ***
gracefully (RE)spawned uWSGI master process (pid: 30509)
spawned uWSGI worker 1 (pid: 30540, cores: 1)
spawned uWSGI worker 2 (pid: 30541, cores: 1)

停掉uwsgi 服务:

sudo uwsgi --stop  uwsgi.pid

平滑重启:

sudo uwsgi --reload uwsgi.pid

nginx 配置

location / { 
	include        uwsgi_params;
	#uwsgi_pass     127.0.0.1:8888;
	uwsgi_pass     unix:///tmp/uwsgi.sock;
	uwsgi_read_timeout 1000;
}   

nginx 配置更改后,重启nginx。
sudo nginx -s reload

参考

http://obmem.info/?p=703
http://www.westphahl.net/blog/2010/4/8/running-django-nginx-and-uwsgi/
uWSGI最新文档

本文原文发自  lovedboy, 转载请保留出处, 谢谢.



你可能感兴趣的:(nginx+uwsgi部署python应用)