1.安装gunicorn
pip install gunicorn
2.保证django的runserver测试环境能运行起来
3.使用gunicorn启动django环境
-
Gunicorn是一个开源Python WSGI UNIX的HTTP服务器,Github仓库地址在这,传说速度快(配置快、运行快)、简单,默认是同步工作,支持Gevent、Eventlet异步,支持Tornado,官方有很详细的文档可以参阅。
- 需要在你的Django项目的settings.py中的INSTALLED_APPS加入:gunicorn
nohup gunicorn --worker-class=gevent isaced.wsgi:application -b 0.0.0.0:1601 &
- --worker-class
指定工作方式,这里我用的gevent
如果提示You need gevent installed to use this worker则表示你还没有安装 gevent。
- isaced.wsgi:application
这里是指你的项目名,在Django创建项目的时候会自动生成对应名字文件夹中的wsgi.py,这里就是指的它。(Python_20160906.wsgi:app)Python_20160905的django项目,里面的app应用
4.更改nginx配置文件
upstream python_villagers.web {
server 127.0.0.1:1601 weight=10 max_fails=2 fail_timeout=30s ;
}
server {
listen 80;
server_name www.x666.com;
access_log /var/log/nginx/x666.log;
location / {
proxy_pass http://python_villagers.web;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static/ {
root /data/isaced; #Django项目所在目录
}
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。