nginx+uwsgi部署python应用

来源:互联网 发布:淘宝客服销售话术大全 编辑:程序博客网 时间:2024/06/03 18:18


uwsgi 配置

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

[uwsgi]#socket = 127.0.0.1:8000 socket = /tmp/uwsgi.sockmaster = truechdir = /home/lovedboy/myproject/ # django工程目录wsgi-file = /home/lovedboy/myproject/myapp/wsgi.pyprocesses = 2listen = 15000enable-threads = truedaemonize = /home/lovedboy/uwsgi/uwsgi.logpidfile = /home/lovedboy/uwsgi/uwsgi.pidpythonpath = /home/lovedboy/myproject/buffer-size =  32768reload-mercy = 8vacuum = truemax-requests = 20000socket-timeout = 20harakiri = 20memory-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:05os: Linux-3.5.0-25-generic #39-Ubuntu SMP Mon Feb 25 19:02:34 UTC 2013nodename: lovedboy machine: i686clock source: unixpcre jit disableddetected number of CPU cores: 4current working directory: /home/lovedboy/uwsgidetected binary path: /usr/local/bin/uwsgiuWSGI 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 31974your memory page size is 4096 bytesdetected max file descriptor number: 65536lock engine: pthread robust mutexesuwsgi socket 0 inherited UNIX address /tmp/uwsgi.sock fd 3Python version: 2.7.3 (default, Apr 10 2013, 05:13:00)  [GCC 4.7.2]Python main interpreter initialized at 0x9fa20f8python threads support enabledyour server socket listen backlog is limited to 10000 connectionsyour mercy for graceful operations on workers is 60 secondsmapped 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, 转载请保留出处, 谢谢.



0 0
原创粉丝点击