采用nginx + virtualenv + gunicorn + django的配置,进程管理使用supervisor
结构图如下:
1.virtualenv虚拟环境中安装gunicorn和django
2.supervisor的配置中配置gunicorn的绝对路径,如下:
[program:djangoProject]
directory=/home/pi/study/python/djangoProject/myproject
command=/home/pi/study/python/djangoProject/bin/gunicorn -c gunicorn_config.py myproject.wsgi:application
user=root
autostart=true
autorestart=true
process_name=%(program_name)s
[program:djangoProject3]
directory=/home/pi/study/python/djangoProject3/myproject
command=/home/pi/study/python/djangoProject3/bin/gunicorn -c gunicorn_config.py myproject.wsgi:application
user=root
autostart=true
autorestart=true
process_name=%(program_name)s
3.gunicorn中的pythonpath配置当前虚拟环境下的python绝对路径,如下:
pythonpath='/home/pi/study/python/djangoProject/bin/python'
bind=':6001'
accesslog='./log/gunicorn_access.log'
errorlog='./log/gunicorn_error.log'
workers=4
threads=4
#access_log_format='%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s "%(f)s" "%(a)s"'
worker_class='gevent'
timeout=120
graceful_timeout=300