django+uwsgi+nginx部署項目,經(jīng)過網(wǎng)上找的資料拼湊后終于使得項目正常跑起來了挟纱,雖然一些配置項中的參數(shù)不太理解羞酗,先做一下相關(guān)配置的記錄,以后在慢慢理解紊服。
1.進(jìn)入虛擬環(huán)境檀轨,安裝uwsgi? pip install uwsgi
2.在項目目錄下創(chuàng)建uwsgi.ini配置文件,配置如下:
[uwsgi]
#項目目錄,填寫到manage.py一級,uwsgi.ini文件也放這一級
chdir=/home/wmy/code/cmeds_git/cmeds/cmeds
#指定項目的application
module=cmeds.wsgi:application
#進(jìn)程個數(shù)
workers=5
pidfile=uwsgi.pid
#指定IP端口
http=127.0.0.1:8080
#指定靜態(tài)文件
static-map=/static=/home/wmy/code/cmeds_git/cmeds/static
#啟動uwsgi的用戶名和用戶組
uid=root
gid=root
#啟用主進(jìn)程
master=true
#自動移除unix Socket和pid文件當(dāng)服務(wù)停止的時候
vacuum=true
#序列化接受的內(nèi)容欺嗤,如果可能的話
thunder-lock=true
#啟用線程
enable-threads=true
#設(shè)置自中斷時間
harakiri=30
#設(shè)置緩沖
post-buffering=4096
buffer-size=65535
#設(shè)置日志目錄
daemonize=uwsgi.log
#指定sock的文件路徑
socket=uwsgi.sock
3.在uwsgi.ini一級啟動uwsgi服務(wù)参萄。uwsgi --ini uwsgi.ini;(關(guān)閉服務(wù)命令:uwsgi --stop uwsgi.pid)
4.安裝nginx, sudo apt-get install nginx
5.啟動nginx(默認(rèn)安裝完已啟動cd /usr/sbin/; sudo nginx)
6.修改nginx配置煎饼,cd /etc/nginx/conf.d; sodu gedit nginx.conf;
server {? #這個server標(biāo)識我要配置了
listen 80;? #我要監(jiān)聽那個端口
server_name 127.0.0.1 ;? #你訪問的路徑前面的url名稱,ip地址(猜測為uwsgi服務(wù)器)
#access_log? /var/log/nginx/access.log? main;? # Nginx日志配置
charset? utf-8; # Nginx編碼
gzip on;? #啟用壓縮,這個的作用就是給用戶一個網(wǎng)頁,比如3M壓縮后1M這樣傳輸速度就會提高很多
gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream;? #支持壓縮的類型
error_page? 404? ? ? ? ? /404.html;? #錯誤頁面
error_page? 500 502 503 504? /50x.html;? #錯誤頁面
#指定項目路徑uwsgi
location / {? ? ? ? #這個location就和咱們Django的url(r'^admin/', admin.site.urls),
include uwsgi_params;? #導(dǎo)入一個Nginx模塊他是用來和uWSGI進(jìn)行通訊的
uwsgi_connect_timeout 30;? #設(shè)置連接uWSGI超時時間
uwsgi_pass unix:/home/wmy/code/cmeds_git/cmeds/cmeds/uwsgi.sock;? #指定uwsgi的sock文件所有動態(tài)請求就會直接丟給他
}
#指定靜態(tài)文件路徑
location /static/ {
alias? /home/wmy/code/cmeds_git/cmeds/cmeds/static;
index? index.html index.htm;
}
}
7.重啟nginx服務(wù);? (cd /usr/sbin; sudo nginx -s stop; sudo nginx)
注:每次修改nginx和uwsgi配置需重啟服務(wù)拧揽;查看服務(wù)是否啟動ps ajx|grep nginx
虛擬環(huán)境為virtulenv+virtulenvwrapper.