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

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

标签(空格分隔): 未分类 django gunicorn supervisor gevent

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

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

    apt-get install nginx,supervisor

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

apt-get install python-dev
  1. 安装django,gunicorn,gevent,使用虚拟环境安装,不要污染了系统库java

  2. 配置gunicornpython

    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

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

  3. supervisor配置django

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

  4. 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;app

    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 发邮件给我!

相关文章
相关标签/搜索