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

來源:互聯網
上載者:User

標籤:

django+nginx+supervisor+gunicorn+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=truecommand= 這裡寫上面gunicorn 的commanddirectory= 網站所在的目錄process_name= top 中顯示的進程名redirect_stderr=truestdot_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 ,

  • 本文來自:Linux學習網

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.