django,nginx,supervisor,gunicorn,gevent這幾個(gè)都是在本領(lǐng)域大名鼎鼎的軟件,下面的部署都是在Ubuntu12.04里面驗(yàn)證成功的!
首先是安裝這些軟件在ubuntu下面都比較簡單,nginx和supservisor的安裝如下
apt-get install nginx,supervisor在ubuntu下使用python,強(qiáng)烈建議安裝python-dev
apt-get install python-dev安裝django,gunicorn,gevent,使用虛擬環(huán)境安裝,不要污染了系統(tǒng)庫
配置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這個(gè)是一個(gè)基本的運(yùn)行配置,不過對(duì)于大多數(shù)網(wǎng)站來說已經(jīng)夠用了
supervisor配置
[program:dyzww]autorestart=truecommand= 這里寫上面gunicorn 的commanddirectory= 網(wǎng)站所在的目錄process_name= top 中顯示的進(jìn)程名redirect_stderr=truestdot_logfile=log文件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 靜態(tài)文件目錄,后面的斜杠必須要/; } 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監(jiān)聽的地址; } access_log log文件;}按照上面的配置,django網(wǎng)站就能夠驅(qū)動(dòng)起來了,靜態(tài)文件全部由nginx處理,只有動(dòng)態(tài)文件需要django處理,這樣大大的增加了性能!小站易讀中文網(wǎng)就是這么驅(qū)動(dòng)的,上面的代碼全部從服務(wù)器中copy過來! 在這里也給小站打個(gè)廣告 http://www.ydzww.com,
大家要是覺得本文寫的對(duì)你有一點(diǎn)點(diǎn)幫助,您轉(zhuǎn)載的時(shí)候保留一下小站的地址,舉手之勞,有疑問的話 yiduzww@126.com 發(fā)郵件給我!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注