django+nginx+supervisor+gunicorn+gevent 网站部署

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

django+nginx+supervisor+gunicorn+gevent 网站部署 django,nginx,supervisor,gunicorn,gevent这几个都是在本领域大名鼎鼎的软件,下面的部署都是在Ubuntu12.04里面验证成功的!

首先是安装这些软件在ubuntu下面都比较简单,nginx和supservisor的安装如下

apt-get install nginx,supervisor

在ubuntu下使用python,强烈建议安装python-dev

apt-get install python-dev

安装django,gunicorn,gevent,使用虚拟环境安装,不要污染了系统库

配置gunicorn

gunicorn app.wsgi:application-w 4 -b :%(PRoxy_port)s -k gevent --max-requests 500 --access-logfile=%(access_log)s --error-logfile=%(error_log)s

这个是一个基本的运行配置,不过对于大多数网站来说已经够用了

supervisor配置

[program:dyzww]

autorestart=true

command= 这里写上面gunicorn 的command

directory= 网站所在的目录

process_name= top 中显示的进程名

redirect_stderr=true

stdot_logfile=log文件

nginx配置

server {

listen 80 default;

server_name _;

default_type application/octet-stream;

gzipon;

gzip_http_version 1.0;

gzip_proxied any;

gzip_min_length 500;

gzip_disable "MSIE [1-6]\.";

gzip_types text/plain text/html text/xmltext/CSStext/comma-separated-values

text/javascript application/x-Javascriptapplication/atom+xml image/jpeg image/gif image/png;

location /static/ {

alias 静态文件目录,后面的斜杠必须要/;

}

location /media/ {

alias 媒体文件目录,后面斜杠必须有/;

expires 30d;

}

location / {

try_files $uri @proxied;

}

location @proxied {

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Host $http_host;

proxy_redirect off;

proxy_pass 这里填写gunicorn监听的地址;

}

access_log log文件;

}

按照上面的配置,django网站就能够驱动起来了,静态文件全部由nginx处理,只有动态文件需要django处理,这样大大的增加了性能!小站易读中文网就是这么驱动的,上面的代码全部从服务器中copy过来! 在这里也给小站打个广告http://www.ydzww.com,

大家要是觉得本文写的对你有一点点帮助,您转载的时候保留一下小站的地址,举手之劳,有疑问的话yiduzww@126.com发邮件给我!

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航