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 發郵件給我!

相關文章
相關標籤/搜索