五步教你实现使用Nginx+uWSGI+Django方法部署Django程序

php中文网
发布: 2016-07-29 09:15:17
原创
1246人浏览过
Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式。在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求。nginx把所有静态请求自己来处理(这是NGINX的强项)。然后,NGINX将所有非静态请求通过uwsgi传递给Django,由Django来进行处理,从而完成一次WEB请求。可见,uwsgi的作用就类似一个桥接器。起到桥梁的作用。

note:不使用nginx,只使用uwsgi+django也是可以实现web服务的。uwsgi也可以直接处理web请求。

为了完成上述的方式部署,我将分成两篇文章来分别进行阐述。
  • 第一步先解决uwsgi与django的桥接。解决在没有nginx的情况下,如何使用uwsgi+DJANGO来实现一个简单的Web服务器

  • 第二步解决uwsgi与Nginx的桥接。通过nginx与uwsgi的桥接,打通nginx与django的连通,从而比较完美的实现django的部署。

  • 本文将分成五步来详细阐述uwsgi+django的部署方式。nginx+uwsgi+django的部署将在下一篇 文章中阐述。本文大纲:
  • 环境介绍
  • 安装uwsgi
  • 测试uwsgi
  • 配置django
  • 连接django和uwsgi,实现简单的Web服务器
  • 环境介绍

  • Ubuntu 12.04.1 LTS
  • django 1.4.2
  • 安装uwsgi

    1.安装pip可以参考这篇文章:http://www.jsxubar.info/install-pip.html2.安装uwsgi
    <spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(187,96,213)">$ </span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(0,112,32)">export </span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(187,96,213)">LDFLAGS</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">=</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(64,112,160)">"-Xlinker --no-as-needed"</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(187,96,213)">$ </span>pip install uwsgi
    
    登录后复制

    测试uwsgi

    在你的机器上写一个test.py
    # test.py
    def application(env, start_response):
        start_response('200 OK', [('Content-Type','text/html')])
        return "Hello World"
    
    登录后复制
    然后执行shell命令:
    uwsgi --http :8001 --wsgi-file test.py
    
    登录后复制
    访问网页:http://127.0.0.1:8001/看在网页上是否有Hello World

    配置django

    NOTE:

    请保证你的django项目是正常使用的。可以使用

    python manage.py runserver 0.0.0.0:8002

    来测试一下你的django项目是否能正常跑起来。

    请保证你的django程序已经关闭。编写django_wsgi.py文件,将其放在与文件manage.py同一个目录下。

    注意: 编写文件时需要注意语句os.environ.setdefault。比如,如果你的项目为mysite,则你的语句应该是 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

    @@######@@

    @@######@@

    连接django和uwsgi,实现简单的Web服务器

    我们假设你的Django项目的地址是/home/work/src/sites/testdjango1/testdjango/mysite,然后,就可以执行以下命令:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    登录后复制
    这样,你就可以在浏览器中访问你的Django程序了。所有的请求都是经过uwsgi传递给Django程序的。

    最后:

    关于如何将uwsgi与Nginx连接,可以期待下篇文章 《五步教你实现使用Nginx+Uwsgi+Django方法部署Django程序(下)》最后面,请大家要支持Django中国社区哦,单靠一两个人是不行的,一起推广一下,让Django社区更有力量哈!更有人气哈!推广链接: http://django-china.cn/

    参考、解释及其它

  • wsgi: WSGI是一种Web服务器网关接口。它是一个Web服务器(如nginx)与应用服务器(如uWSGI服务器)通信的一种规范。

    关于WSGI协议看这里:WSGI

  • uWSGI: http://uwsgi-docs.readthedocs.org/en/latest/index.html uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议。 Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换。

  • uwsgi: uwsgi同WSGI一样是一种通信协议,而uWSGI是实现了uwsgi和WSGI两种协议的Web服务器

    uwsgi协议是一个uWSGI服务器自有的协议,它用于定义传输信息的类型(type of information),每一个uwsgi packet前4byte为传输信息类型描述,它与WSGI相比是两样东西。

    关于uwsgi协议看这里:The uwsgi protocol

  • 有了uWSGI为什么还需要nginx?

    nginx具备优秀的静态内容处理能力,然后将动态内容转发给uWSGI服务器,这样可以达到很好的客户端响应。

    法语写作助手
    法语写作助手

    法语助手旗下的AI智能写作平台,支持语法、拼写自动纠错,一键改写、润色你的法语作文。

    法语写作助手 31
    查看详情 法语写作助手
  • 参考文献:http://heipark.iteye.com/blog/1750970

  • 当然,单单只有uWSGI是不够的,在实际的部署环境中,Nginx是必不可少的工具。

    在本篇文章中,我将一直延用“N步法”的风格来阐述如何将uWSGI与Nginx做连接来部署Django程序。并在最后,会较为完整的阐述本社区的部署方法。本文大纲:
  • 环境介绍
  • 配置uWSGI
  • 配置Nginx
  • Nginx+uWSGI+Django的实现方式
  • 一些建议
  • 环境介绍

  • Ubuntu 12.04.1 LTS
  • django 1.4.2
  • nginx/1.2.6
  • uWSGI 1.4.4
  • 关于uWSGI的安装可参见上一篇文章 上一篇文章《五步教你实现使用Nginx+uWSGI+Django方法部署Django程序(上)》我们假定你已经安装好Nginx了。

    配置uWSGI

    在上一篇文章《五步教你实现使用Nginx+uWSGI+Django方法部署Django程序(上)》中,我们是直接使用命令行来启动uWSGI,在实际部署环境中,我们常用的是配置文件的方式,而非命令行的方式。我的一般做法是用命令行来测试是否uWSGI安装成功,然后用配置文件来真正部署。另外,为了实现Nginx与uWSGI的连接,两者之间将采用soket来通讯方式。在本节中,我们将使用uWSGI配置文件的方式来改进uWSGI的启动方式。假定你的程序目录是 /home/work/src/sites/testdjango1/testdjango/mysite我们将要让Nginx采用8077端口与uWSGI通讯,请确保此端口没有被其它程序采用。注意,请确定你在上一节《五步教你实现使用Nginx+uWSGI+Django方法部署Django程序(上)》中的django_wsgi.py文件已经存在了。新建一个XML文件:djangochina_socket.xml,将它放在 /home/work/src/sites/testdjango1/testdjango/mysite 目录下:
    <spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(96,160,176); font-style:italic">#!/usr/bin/env python</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(96,160,176); font-style:italic"># coding: utf-8</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(0,112,32); font-weight:bold">import</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(14,132,181); font-weight:bold">os</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(0,112,32); font-weight:bold">import</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(14,132,181); font-weight:bold">sys</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(96,160,176); font-style:italic"># 将系统的编码设置为UTF8</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(0,112,32)">reload</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">(</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">sys</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">)</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">sys</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">setdefaultencoding</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">(</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(64,112,160)">'utf8'</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">)</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">os</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">environ</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">setdefault</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">(</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(64,112,160)">"DJANGO_SETTINGS_MODULE"</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">,</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(64,112,160)">"mysite.settings"</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">)</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(0,112,32); font-weight:bold">from</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(14,132,181); font-weight:bold">django.core.handlers.wsgi</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(0,112,32); font-weight:bold">import</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">WSGIHandler</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">application</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">=</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">WSGIHandler</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">()</span>
    登录后复制
    在上面的配置中,我们使用 uwsgi.log 来记录日志,开启4个进程来处理请求。这样,我们就配置好uWSGI了。

    配置Nginx

    我们假设你将会把Nginx程序日志放到你的目录/home/work/var/test/logs/下,请确保该目录存在。我们假设你的Django的static目录是/home/work/src/sites/testdjango1/testdjango/collectedstatic/ , media目录是/home/work/src/sites/testdjango1/testdjango/public/media/,请确保这些目录存在。我们假设你的域名是 www.you.com (在调试时你可以设置成你的机器IP)我们假设你的域名端口是 80(在调试时你可以设置一些特殊端口如 8070)基于上面的假设,我们为conf/nginx.conf添加以下配置
    uwsgi --http :8000 --chdir /home/work/src/sites/testdjango1/testdjango/mysite --module django_wsgi
    
    登录后复制
    在上面的设置后,可以让Nginx来处理静态文件(/static/ 和 /media/ )。非静态文件请求Nginx会发给 socket 8077,然后让uWSGI来进行处理。

    Nginx+uWSGI+Django的实现方式

    在完成上面配置后,需要按以下步骤来做:
  • 重启Nginx服务器,以使Nginx的配置生效。

    <spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold"><uwsgi></span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold"><socket></span>:8077<spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold"></socket></span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold"><chdir></span>/home/work/src/sites/testdjango1/testdjango/mysite<spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold"></chdir></span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold"><module></span>django_wsgi<spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold"></module></span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold"><processes></span>4<spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold"></processes></span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(96,160,176); font-style:italic"><!-- 进程数 --></span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold"><daemonize></span>uwsgi.log<spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold"></daemonize></span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold"></uwsgi></span>
    登录后复制

    重启后检查Nginx日志是否有异常。

  • 启动uWSGI服务器

    <spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">server</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">{</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">listen</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(64,160,112)">80</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">server_name</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">www</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">you</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">com</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">access_log</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">home</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">work</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">var</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">test</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">logs</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">access</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">log</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">error_log</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">home</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">work</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">var</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">test</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">logs</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">error</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">log</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(64,160,112)">#charse</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">t</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">koi8</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">-</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">r</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(64,160,112)">#access</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">_log</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">logs</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">host</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">access</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">log</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">main</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">location</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">{</span><spanPalatino Linotype',Times,'Times New Roman',serif!important"><strong>include</strong></span><spanPalatino Linotype',Times,'Times New Roman',serif!important">uwsgi_params</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">uwsgi_pass</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(64,160,112)">127</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(64,160,112)">0</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(64,160,112)">0</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(64,160,112)">1</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">:</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(64,160,112)">8077</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">}</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,126)">#error_page</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">404</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">404</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(14,132,181); font-weight:bold">.html</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">#</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">redirect</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">server</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">error</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">pages</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">to</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">the</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">static</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">page</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">50x</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(14,132,181); font-weight:bold">.html</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">#</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">error_page</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">500</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">502</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">503</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">504</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">50x</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(14,132,181); font-weight:bold">.html</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">location</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">=</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">50x</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(14,132,181); font-weight:bold">.html</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">{</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">root</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">html</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">}</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">location</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">static</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">{</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">alias</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">home</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">work</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">src</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">sites</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">testdjango1</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">testdjango</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">collectedstatic</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">index</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">index</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">html</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">index</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">.</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">htm</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">}</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">location</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(6,40,115); font-weight:bold">media</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">{</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">alias</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">home</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">work</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">src</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">sites</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">testdjango1</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">testdjango</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">public</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">media</span><spanPalatino Linotype',Times,'Times New Roman',serif!important; color:rgb(102,102,102)">/</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">;</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">}</span><spanPalatino Linotype',Times,'Times New Roman',serif!important">}</span>
    登录后复制

    检查日志 uwsgi.log 是否有异常发现。

  • 访问服务

    基于上面的假设你的域名是www.you.com

    因此,我们访问 www.you.com,如果发现程序与 单独使用Django启动的程序一模一样时,就说明成功啦!

  • 关闭服务的方法

    将uWSGi进程杀死即可。

  • 一些建议

  • uWSG配置文件的进程数,可以根据实际情况分配。不要开得太大,否则机器可能会内存耗用太高。一般来说,对于一个小社区来说,4个进程已经足够了。

  • 一般情况下,可以编写一下 stop.sh 脚本 来关闭uWSGI。

  • 以上就介绍了五步教你实现使用Nginx+uWSGI+Django方法部署Django程序,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

    nginx -s  reload
    
    登录后复制
    cd /home/work/src/sites/testdjango1/testdjango/mysite
    
    uwsgi -x djangochina_socket.xml
    
    登录后复制
    相关标签:
    最佳 Windows 性能的顶级免费优化软件
    最佳 Windows 性能的顶级免费优化软件

    每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

    下载
    来源:php中文网
    本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
    最新问题
    开源免费商场系统广告
    热门教程
    更多>
    最新下载
    更多>
    网站特效
    网站源码
    网站素材
    前端模板
    关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送
    PHP中文网APP
    随时随地碎片化学习

    Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号