NGINX+UWSGI部署生產的DJANGO代碼

而且NGINX不用ROOT賬戶喲。html

1,編譯安裝NGINX及UWSGI及DJANGO,不表述nginx

2,將NGINX文件夾更改成普通用戶擁有。但執行文件NGINX仍爲ROOT,運行以下命令加入特殊權限標誌位,並將NGINX.CONF的USER設置普通用戶及組(空格隔開):web

chmod u+x nginx

  

3,在NGINX裏配置UWSGI的PROXYbash

upstream p_host {
    server 127.0.0.1:9090;
}

server {
        listen       80;
        server_name  localhost;
        
        location / {            
            include  uwsgi_params;
            uwsgi_pass  prism_host; 
            uwsgi_param UWSGI_SCRIPT P.wsgi;  //這裏定義wsgi.py文件
            uwsgi_param UWSGI_CHDIR /P/P;    //這裏定義DJANGO的MANAGER目錄
            index  index.html index.htm;
            client_max_body_size 35m;
        }
	location ^~ /static {
            	root /P/P;  //定義靜態資源文件位置
        }
    }

  

4,配置UWSGI9090.INI文件(保證相關文件夾存在且有權限,爲何要多不一樣的端口呢,由於這樣能夠在一個服務器上配置多個端口,多個DJANGO應用)服務器

[uwsgi]
socket = 127.0.0.1:9090
master = true
vhost = true
no-stie = true
workers = 4
reload-mercy = 10
vacuum = true    
max-requests = 1000
limit-as = 512
buffer-sizi = 30000
pidfile = /usr/local/nginx/run/uwsgi9090.pid   
daemonize = /uwsgi9090.log

  

5,生成執行腳本UWSGI9090文件(保證相關文件夾存在且有權限,這個原本能夠放到SERVICE的INIT.D目錄下,但爲了避免污染管理員用戶,本身先用普通用戶)app

#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for uwsgi webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f uwsgi defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add uwsgi'
 
### BEGIN INIT INFO
# Provides:          uwsgi
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the uwsgi web server
# Description:       starts uwsgi using start-stop-daemon
### END INIT INFO
 
# Author:   licess
# website:  http://lnmp.org
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="uwsgi daemon"
NAME=uwsgi9090
DAEMON=/usr/local/bin/uwsgi
CONFIGFILE=/usr/local/nginx/conf/conf.d/$NAME.ini  //定義位置
PIDFILE=/usr/local/nginx/run/$NAME.pid  //定義位置
SCRIPTNAME=/usr/local/nginx/sbin/$NAME  //定義位置
 
set -e
[ -x "$DAEMON" ] || exit 0
 
do_start() {
    $DAEMON $CONFIGFILE || echo -n "uwsgi already running"
}
 
do_stop() {
    $DAEMON --stop $PIDFILE || echo -n "uwsgi not running"
    rm -f $PIDFILE
    echo "$DAEMON STOPED."
}
 
do_reload() {
    $DAEMON --reload $PIDFILE || echo -n "uwsgi can't reload"
}
 
do_status() {
    ps aux|grep $DAEMON
}
 
case "$1" in
 status)
    echo -en "Status $NAME: \n"
    do_status
 ;;
 start)
    echo -en "Starting $NAME: \n"
    do_start
 ;;
 stop)
    echo -en "Stopping $NAME: \n"
    do_stop
 ;;
 reload|graceful)
    echo -en "Reloading $NAME: \n"
    do_reload
 ;;
 *)
    echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2
    exit 3
 ;;
esac
 
exit 0

uwsgi9090

  

6,平常更新重啓(可能須要創建軟連接),中止操做。socket

/usr/local/nginx/sbin/nginx

/usr/local/nginx/sbin/nginx -s reload

/usr/local/nginx/sbin/nginx -s stop

sh /usr/local/nginx/sbin/uwsgi9090 start

sh /usr/local/nginx/sbin/uwsgi9090 stop

sh /usr/local/nginx/sbin/uwsgi9090 reload
相關文章
相關標籤/搜索