[关闭]
@xuemy268 2016-09-15T15:17:01.000000Z 字数 1483 阅读 2582

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

未分类

django gunicorn supervisor gevent

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

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

    apt-get install nginx,supervisor

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

    apt-get install python-dev

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

  3. 配置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

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

  4. supervisor配置

    [program:dyzww]
    autorestart=true
    command= 这里写上面gunicorn 的command
    directory= 网站所在的目录
    process_name= top 中显示的进程名
    redirect_stderr=true
    stdot_logfile=log文件

  5. nginx配置

    server {
    listen 80 default;
    server_name _;
    default_type application/octet-stream;
    gzip on;
    gzip_http_version 1.0;
    gzip_proxied any;
    gzip_min_length 500;
    gzip_disable "MSIE [1-6].";
    gzip_types text/plain text/html text/xml text/css
    text/comma-separated-values
    text/javascript application/x-javascript
    application/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 发邮件给我!

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注