安装:
pip install gunicorn
启动应用:
gunicorn -w 3 -k gthread -e DJANGO_SETTINGS_MODULE=settings.prod Server.wsgi -b 0.0.0.0:8005 debug方式: gunicorn -w 3 -k gthread -e DJANGO_SETTINGS_MODULE=settings.prod Server.wsgi -b 0.0.0.0:8005 --preload
参数说明:
-w : 启动线程数量
-k: 指定线程类型
-e: 指定环境变量
-b: 绑定的地址和端口
注意点:
如果你的配置文件目录发生了变化, 需要修改wsgi.py文件 然后启动的时候只需要执行wsgi
然后使用supervisor进行进程管理:
[program:server] directory=/data/www/server/ command=/data/www/server/env/bin/gunicorn -w 3 -k gthread -e DJANGO_SETTINGS_MODULE=settings.prod Server.wsgi -b :8005 process_name=server-%(process_num)d stdout_logfile=/var/log/supervisord/server_out.log ; stdout log path, NONE for none; default AUTO stdout_logfile_maxbytes=100MB ; max # logfile bytes b4 rotation (default 50MB) stdout_logfile_backups=5 ; # of stdout logfile backups (0 means none, default 10) stderr_logfile=/var/log/supervisord/server_err.log ; stderr log path, NONE for none; default AUTO stderr_logfile_maxbytes=100MB ; max # logfile bytes b4 rotation (default 50MB) stderr_logfile_backups=5 ; # of stderr logfile backups (0 means none, default 10)