nginx+uwsgi+django部署

1、nginx.conf配置文件 server里增加:

location / {

      include /etc/nginx/uwsgi_params;

      uwsgi_pass 127.0.0.1:8088;

      uwsgi_read_timeout 20;

}

2、项目settings.py同目录下创建wsgi.py文件:

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

3、创建uwsgi.ini文件:

[uwsgi]

socket = :8088

chmod-socket = 666

chdir = /path/to/project

wsgi-file = /path/to/project/wsgi.py

module = project.wsgi.application

master = true

vhost = true

no-site = true

pythonpath = /usr/local/lib/python2.7/site-packages/

enable-threads = true

processes = 1

threads = 8

pidfile = /path/to/project/lin.pid

vacuum = true

py-autoread = 1

max-requests = 2000

listen = 1024

4、项目启动

uwsgi --ini /path/to/uwsgi.ini --daemonize /path/to/accesslog/uwsgi.log

/etc/init.d/nginx start

备注:

uwsgi.ini里最后一行:listen=1024 表示设置uWSGI listen queue(缺省值是100)。此外还需要修改系统配置:

vim /etc/sysctl.conf

在文件最后添加一行记录net.core.somaxconn = 1024

执行sysctl -p重新load参数设置,这样会立即生效

如果连接数超过listen值,则会在uwsgi日志里报错:

Sun Feb  5 12:22:21 2017 - *** uWSGI listen queue of socket ":8088" (fd: 3) full !!! (101/100) ***

你可能感兴趣的:(nginx+uwsgi+django部署)