django + nginx + uwsgi部署

一直用python manage.py方式跑項目代碼,因涉及到http api接口,現需要用nginx+uwsgi代理訪問......  這個東西不弄不知道,一弄嚇一跳;;崩潰的心都有啊........


版本:

nginx: 1.2.1

uwsgi: 1.9.20

django: 1.6.4


工程目錄:/var/www/oms

工程APP目錄:  /var/www/oms/asset

uwsgi配置文件目錄: /var/www/oms/uwsgi


1.工程目錄放置正確,不然就無厘頭事件各種有

/var/www/oms

      //因採用ini配置文件,在配置文件中有一項chdir配置,在剛開始設置報錯提示chdir權限拒絕,查了下,說沒有執行權限,需要chmo -R +x,但是有那麼點不好,就有人推薦放在/var/www、/home/xxx目錄,那我就選擇了放在/var/www,之前是放在/opt/www


2.配置uwsgi,採用ini配置文件

cat /var/www/oms/uwsgi/uwsgi.ini

[uwsgi]

chdir=/var/www/oms                          //工程目錄

module=oms.wsgi:application           //加載的wsgi模塊,使用默認的

master=True                                        //開啓master process

pidfile=/var/run/oms.pid                   //pid文件位置

vacuum=True                                     //服務器退出時自動清除通用文件和socket

max-requests=5000                           //最大請求

daemonize=/opt/log/uwsgi/oms.log   //後臺運行日誌輸出位置

socket = :9090                                   //監聽於全局9090端口,可以改爲socket運行,比較快!~


上述配置好,就剩下nginx vhost配置文件了


3.配置nginx,代理uwsgi

cat /usr/local/nginx/conf/vhost/oms.conf

server

     {

        listen 10086;

        server_name X.X.X.X;

        location /static/ {

          root /var/www/oms;

        }

        location / {

          root /var/www/oms;

          include uwsgi_params;

          uwsgi_pass 127.0.0.1:9090;

        }

        access_log /opt/log/nginx/oms.log;

     }

啓動nginx:  /etc/init.d/nginx start ;  確保nginx無誤


4. 啓動uwsgi

cat /etc/init.d/uwsgi

#!/bin/bash

PID=/var/run/oms.pid

LOG=/opt/log/uwsgi

CONF=/var/www/oms/uwsgi/uwsgi.ini

 

case "$1" in

  start)

    echo "Starting uwsgi"

    uwsgi --ini $CONF --uid 501 &> /dev/null

    ;;

  stop)

    echo "Stopping uwsgi"

    killall -QUIT uwsgi &> /dev/null

    ;;

  restart)

    $0 stop

    sleep 1

    $0 start

    ;;

  *)

    echo "usage: $0 {start|stop|restart}"

esac

exit 0 

/etc/init.d/uwsgi start

cat /opt/log/uwsgi/oms.log,查看是否有錯誤

ps -ef | grep uwsgi, 是否啓動成功

最後直接可以訪問了,http://X.X.X.X:10086


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章