欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

阿里云ECS服務(wù)器部署django的方法

 更新時(shí)間:2019年08月29日 16:09:28   作者:fengyu09  
今天小編就為大家分享一篇阿里云ECS服務(wù)器部署django的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

參考

服務(wù)器安裝的是Centos 系統(tǒng)。

uwsgi是使用pip安裝的。

nginx是使用yum install nginx安裝。

python 2.7, mysql 5.5使用 yum安裝。

它們之間的邏輯關(guān)系如下:

the web client <-> the web server <-> the socket <-> uwsgi <-> Django

uswgi負(fù)責(zé)從Django拿內(nèi)容,通過(guò)socket傳給 web server如nginx, 最后顯示到 網(wǎng)頁(yè)瀏覽器。

在django的項(xiàng)目下,建文件 uswgi.ini,可以不用在uswgi后面寫(xiě)一串選項(xiàng)。

# uwsgi.ini file
[uwsgi]
 
# Django-related settings
# the base directory (full path)
chdir   = /var/www/html/
# Django's wsgi file
module   = app.wsgi:application
# process-related settings
# master
master   = true
# maximum number of worker processes
processes  = 10
# the socket (use the full path to be safe
#socket   = 127.0.0.1:8001
socket = /tmp/site.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum   = true
process = 4
threads = 2

# Django's wsgi file這個(gè)對(duì)應(yīng)你自己Django項(xiàng)目的就好。 chdir就是Django的所在目錄,和manage.py同一目錄。

其他可以默認(rèn)。

同樣建立nginx.conf

# nginx.conf
 
# the upstream component nginx needs to connect to
upstream django {
 server unix:///tmp/site.sock; # for a file socket
 #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
 
# configuration of the server
server {
 # the port your site will be served on
 listen  80;
 # the domain name it will serve for
 server_name demo.mmm.com; # substitute your machine's IP address or FQDN
 charset  utf-8;
 
 # max upload size
 client_max_body_size 128M; # adjust to taste
 
 # Django media
 location /media {
  alias /var/www/html/media; # your Django project's media files - amend as required
 }
 
 location /static {
  alias /var/www/html/static; # your Django project's static files - amend as required
 }
 
 # Finally, send all non-media requests to the Django server.
 location / {
  uwsgi_pass django;
  include  /var/www/html/uwsgi_params; # the uwsgi_params file you installed
 }
}

uwsgi_pass django; 中的django和upstream django 相對(duì)應(yīng)。

兩頭的socket名字要一樣。uwsgi里要改sock的權(quán)限為666,默認(rèn)的664,nginx會(huì)連不上,在/var/log/nginx/error.log里可以看到connect is denied。

據(jù)說(shuō)使用socket比端口要好,注意unix://這個(gè)前綴,加上后面sock的路徑,是3個(gè)///,看起來(lái)不好看。

無(wú)論使用socket還是TCP端口,uwsgi的socket和nginx的server值要對(duì)應(yīng),否則沒(méi)法接通路徑。

server_name demo.mmm.com; 看文章時(shí),把server_name這個(gè)詞看成域名,給修改掉,結(jié)果nginx啟動(dòng)失敗??梢杂糜蛎蛘逫P。

ln -s /var/www/html/nginx.conf /etc/nginx/conf.d/

鏈接后,這樣在conf.d 配置目錄里會(huì)有Django下建立的nginx.conf,比較方便。

uwsgi_params文件在/etc/nginx下面有,老外說(shuō)是拷貝到Django目錄下,不知道直接使用會(huì)有什么區(qū)別。

最后:

使用chkconfig nginx on 把nginx設(shè)置成自啟動(dòng)服務(wù)。

在/etc/rc.local里加一行 uwsgi /var/www/html/uwsgi.ini --uid www --gid www

我沒(méi)加uid和gid,以root運(yùn)行uwsgi會(huì)被警告的。

原來(lái)是打算用apache的,所以有個(gè)/var/www/html目錄。mod-python報(bào)錯(cuò)后,不知道怎么處理。

系統(tǒng)自帶Python2.6,mod-python就是調(diào)用的2.6。

nginx不能從uwsgi獲得數(shù)據(jù)時(shí),就會(huì)輸出nginx的默認(rèn)頁(yè)面。還會(huì)輸出 Bad Gateway提示。

linux最大的麻煩是,程序和配置文件分散,裝好一個(gè)程序,都不知道它在哪里。

以上這篇阿里云ECS服務(wù)器部署django的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論