国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 服務(wù)器 > Web服務(wù)器 > 正文

Django在Ubuntu14.04的部署方法

2024-09-01 13:52:22
字體:
供稿:網(wǎng)友

第一步。

sudo apt-get update

sudo apt-get upgrade

先更新。。

Django的主流部署方式:nginx+uwsgi+django

第二步,安裝nginx

sudo apt-get install nginx

安裝nginx,如果需要安裝最新的nginx需從官網(wǎng)下載源碼包進(jìn)行手動(dòng)編譯。

nginx的大致文件結(jié)構(gòu)。

1.配置文件:/etc/nginx

2.程序:/usr/sbin/nginx

3.日志:/var/log/nginx/access.log - error.log

第三步,安裝uwsgi

sudo apt-get install python3-dev

sudo apt-get install python3-pip

sudo pip3 install uwsgi(此步之前,可以換下pip源以提高下載速度。在~/.pip下創(chuàng)建pip.conf寫入

[global]

trusted-host = pypi.douban.com

index-url = http://pypi.douban.com/simple)

uwsgi是一個(gè)web服務(wù)器,它實(shí)現(xiàn)了WSGI協(xié)議、uwsgi、http等協(xié)議。Nginx中HttpUwsgiModule的作用是與uWSGI服務(wù)器進(jìn)行交換。

大致流程是 : 客戶端<==>nginx<==>uwsgi<==>Django。靜態(tài)請(qǐng)求由Nginx自己處理。非靜態(tài)請(qǐng)求通過uwsgi傳遞給Django,由Django來進(jìn)行處理,從而完成一次WEB請(qǐng)求。

創(chuàng)建Django測(cè)試項(xiàng)目,django-admin startproject mysite,cd mysite,python manage.py startapp demo1。

第四步,測(cè)試uwsgi

在mysite目錄下新建測(cè)試文件,nano test.py.

寫入:

def application(env, start_response):  start_response('200 OK', [('Content-Type','text/html')])  return ["Hello World"]

運(yùn)行:

uwsgi --http :8001 --plugin python --wsgi-file test.py

訪問正常。

第五步,測(cè)試Django

python manage.py runserver 0.0.0.0:8002

訪問正常。

連接Django和uwsgi。

uwsgi --http:8001 --plugin python --module mysite.wsgi

訪問正常。

第六步,配置uwsgi

uwsgi支持通過多種配置文件形式啟動(dòng),這里采用ini配置文件的方法.

新建uwsgi:nano uwsgi.ini

# mysite_uwsgi.ini file  [uwsgi]  socket = 127.0.0.1:3400  # Django-related settings  # the django project directory (full path)  chdir      = /home/ubuntu/mysite  # Django's wsgi file  module     = mysite.wsgi  # process-related settings  # master  master     = true  # maximum number of worker processes  processes    = 2  threads = 2  max-requests = 6000  # ... with appropriate permissions - may be needed  chmod-socket  = 664  # clear environment on exit  vacuum     = true

訪問時(shí)報(bào)錯(cuò),invalid request block size: 21573 (max 4096)...skip。

原因是url地址超過4096個(gè)字符,原因是我們是用socket的方式啟動(dòng),將配置文件的socket改為http即可,或者修改buffer-size。

(建議不做修改,測(cè)試時(shí)改為http即可,等連接nginx時(shí),改回到socket)

daemonize = /home/ubuntu/mysite/uwsgi.log

正式運(yùn)行時(shí)將這句代碼加入到uwsgi.ini文件中,訪問日志就會(huì)后臺(tái)輸出到uwsgi.log

此時(shí)django已經(jīng)能訪問。

第七步,配置nginx

修改nginx的默認(rèn)配置文件/etc/nginx/sites-enabled/default

server {  # the port your site will be served on  listen   80;  # the domain name it will serve for  server_name 127.0.0.1; # substitute your machine's IP address or FQDN  charset   utf-8;  # max upload size  client_max_body_size 75M;  # adjust to taste  # Django media  location /media {    alias /home/ubuntu/mysite/media; # your Django project's media files - amend as required  }  location /static {    alias /home/ubuntu/mysite/static; # your Django project's static files - amend as required  }  # Finally, send all non-media requests to the Django server.  location / {    include   uwsgi_params; # the uwsgi_params file you installed    uwsgi_pass 127.0.0.1:8001;#此處跟uwsgi配置文件保持一致  }}

記得修改測(cè)試時(shí)的uwsgi.ini的配置。

第八步,運(yùn)行

重啟nginx,運(yùn)行uwsgi.

大功告成

以上這篇Django在Ubuntu14.04的部署方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持VEVB武林網(wǎng)。


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 汽车| 荃湾区| 新竹市| 江川县| 丰顺县| 建水县| 三明市| 桦南县| 汉寿县| 黑水县| 板桥市| 龙胜| 安康市| 临洮县| 皮山县| 白河县| 马尔康县| 平原县| 迁安市| 江口县| 东平县| 和林格尔县| 石泉县| 出国| 宁阳县| 九寨沟县| 辽中县| 天峨县| 马关县| 壶关县| 淮南市| 贵溪市| 松滋市| 达日县| 甘泉县| 溧水县| 剑阁县| 政和县| 汉寿县| 南川市| 宜都市|