成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Django-Nginx-uwsgi

羅志環(huán) / 1972人閱讀

摘要:安裝創(chuàng)建文件創(chuàng)建配置文件啟動(dòng)也可編寫啟動(dòng)腳本配置文件,添加下面一行內(nèi)容在新建文件重新啟動(dòng)訪問(wèn)頁(yè)面測(cè)試調(diào)試過(guò)程中,報(bào)錯(cuò)多多查看日志排錯(cuò)。

在開發(fā)環(huán)境下調(diào)試好python項(xiàng)目之后,把項(xiàng)目遷移到nginx上面 首先把django admin的靜態(tài)文件目錄復(fù)制一份到你設(shè)置的static文件目錄下:
python manage.py collectstatic
關(guān)閉settings.py中的debug,關(guān)閉debug之后staticfiles就不生效了,需要在nginx配置靜態(tài)文件的訪問(wèn)。 安裝uwsgi
pip install uwsgi
創(chuàng)建wsgi文件:
root@server1 testweb]# pwd

/Django/testweb

[root@server1 testweb]# cat wsgi.py

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testweb.settings")

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()
創(chuàng)建ini配置文件:
[root@server1 testweb]# pwd

/Django/testweb

[root@server1 testweb]# cat app.ini

[uwsgi]

chdir = /Django/testweb/

;wsgi-file = /Django/testweb/wsgi.py

module = testweb.wsgi

socket = 127.0.0.1:3400

;socket = /var/log/%(project).sock

chmod-socket = 664

;http = 0.0.0.0:8001

;stats = 0.0.0.0:8001

master = true

processes = 4

threads = 2

max-requests = 6000

vacuum = true

pidfile = /var/log/uwsgi.pid;

daemonize = /var/log/uwsgi.log
啟動(dòng)uwsgi:
[root@server1 testweb]# uwsgi --ini app.ini 
也可編寫uwsgi啟動(dòng)腳本:
[root@server1 ~]# cat /etc/init.d/uwsgi 

uwsgi_path=/usr/bin/uwsgi

uwsgi_ini=/Django/testweb/app.ini

uwsgi_pid=/var/log/uwsgi.pid

if [ ! -n $1 ]

then

 echo "Usages: [start|stop|restart]"

 exit 0

fi

if [ $1 = start ]

then

 psid=`ps aux | grep "zh" | grep -v "grep" | wc -l`

 if [ $psid -gt 4 ]

 then

 echo "uwsgi is running!"

 exit 0

 else

 uwsgi --ini $uwsgi_ini

 echo "Start uwsgi service [OK]"

 fi

elif [ $1 = stop ];then

 killall -s INT uwsgi

 echo "Stop uwsgi service [OK]"

elif [ $1 = restart ];then

 #killall -s INT uwsgi

 #uwsgi --ini uwsgi_ini

 kill -HUP $uwsgi_pid

 echo "Restart uwsgi service [OK]"

else

 echo "Usages: [start|stop|restart]"

fi

[root@server1 ~]# cat /etc/init.d/uwsgi 

uwsgi_path=/usr/bin/uwsgi

uwsgi_ini=/Django/testweb/app.ini

uwsgi_pid=/var/log/uwsgi.pid

if [ ! -n $1 ]

then

 echo "Usages: [start|stop|restart]"

 exit 0

fi

if [ $1 = start ]

then

 psid=`ps aux | grep "zh" | grep -v "grep" | wc -l`

 if [ $psid -gt 4 ]

 then

 echo "uwsgi is running!"

 exit 0

 else

 uwsgi --ini $uwsgi_ini

 echo "Start uwsgi service [OK]"

 fi

elif [ $1 = stop ];then

 killall -s INT $uwsgi_path

 echo "Stop uwsgi service [OK]"

elif [ $1 = restart ];then

 #killall -s INT uwsgi

 #uwsgi --ini uwsgi_ini

 kill -HUP $uwsgi_pid

 echo "Restart uwsgi service [OK]"

else

 echo "Usages: [start|stop|restart]"

fi
配置nginx.conf文件,添加下面一行內(nèi)容:
 include /usr/local/nginx/conf/conf.d/*;
在conf.d新建app.conf文件:
[root@server1 conf.d]# cat app01.conf 

server {

listen 80;

server_name localhost; 

charset utf-8;

access_log logs/testweb/app01/access_log;

error_log logs/testweb/app01/error_log;

client_max_body_size 75M; # adjust to taste

#location /admin {

#alias /Django/testweb/static/admin

# }

location /static {

alias /Django/testweb/static; # your Django project"s static files - amend as required

}

# Finally, send all non-media requests to the Django server.

location / {

 uwsgi_pass 127.0.0.1:3400;

 include uwsgi_params; # the uwsgi_params file you installed

}

}
重新啟動(dòng)Nginx:
[root@server1 conf.d]# /etc/init.d/nginx stop

[root@server1 conf.d]# /etc/init.d/nginx start
訪問(wèn)頁(yè)面測(cè)試:


調(diào)試過(guò)程中,報(bào)錯(cuò)多多查看日志排錯(cuò)。

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/41596.html

相關(guān)文章

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<