Fork me on GitHub

Ubuntu + Django + Nginx + uwsgi


 

环境

  Ubuntu 14.04

  Python 2.7

  Django 1.8.4

 


1 安装Nginx

         sudo apt-get install nginx 

 

  测试   sudo /etc/init.d/nginx start         stop、restart 或者  sudo serivce nginx start /stop/restart 

       默认开启0.0.0.0:80

 

 


2 安装uwsgi

sudo apt-get install python-dev   #!不安装下面可能会出错

pip install uwsgi

  测试  sudo uwsgi --http :8000 --wsgi-file test.py 

test.py


def application(env, start_response):
  start_response = ("200 OK", [('Content-Type', 'text/html')])
  return "Hello UWSGI!"  #python2

  #return [b"Hello World"] # python3

 

3 基于Nginx和uwsgi部署Django

  原理   the web client <-> the web server(nginx) <-> the socket <-> uwsgi <-> Django 

     

  若第2步能成功,说明 the web client <-> uWSGI <-> Python 是畅通的

 

  确认Django的project本身没问题  python manage.py runserver 0.0.0.0:8000 

 

  使用uwsgi把project拉起来  uwsgi --http :8000 --module mysite.wsgi 

 

    

  

 

posted @ 2015-11-03 12:21  Roronoa__Zoro  阅读(180)  评论(0)    收藏  举报