码迷,mamicode.com
首页 > 其他好文 > 详细

Start Your Django Project in Nginx with uWsgi

时间:2014-09-30 14:00:39      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   strong   for   

Step 0:Install A,B,C,blabla needed

This can be seen in my another article in the blog.click here(unavailable now,just in the future)

 

Step 1:Create A Django Project

chdir /path/to/your/project/base/

django-admin.py startproject mysite

 

Step 2:Create Your uwsgi congfigure files and Edit them

chdir /path/to/your/project/base/mysite

touch mysite_uwsgi.conf mysite_uwsgi.py mysite_uwsgi.ini mysite_mysite_uwsgi.pid uwsgi.pid

sudo ln -s /path/to/your/project/base/mysite/mysite_uwsgi.conf /etc/nginx/sites-enabled/ # so that this configuration can be included into nginx‘s conf

# sudo ln -s /path/to/your/project/base/mysite/mysite_uwsgi.conf /etc/nginx/sites-enabled/mysite_nginx.conf # another name is also ok!

## ------------------------------------------------------------------------------------------------------------------------

vim mysite_uwsgi.conf

# mysite_uwsgi.conf
server {
    listen         8000; 
    server_name    10.10.10.132; # after all of these steps,type http://10.10.10.132:8000/ into your browser to get what you want(ps.10.10.10.132 if my IP)
    charset UTF-8;
 
    client_max_body_size 75M;
 
    location / { 
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:8001; # nginx(not you) wiil get something from 127.0.0.1:8001 then return to you
        uwsgi_read_timeout 2;
    }   
    location /static {
        expires 30d;
        autoindex on; 
        add_header Cache-Control private;
        alias /path/to/your/project/base/mysite/mysite/static/;
     }
 }

  

# ln this file into the ‘/path/to/nginx/site-enable/‘ (have done in step 2 ‘sudo ln blablablabla‘)

## ------------------------------------------------------------------------------------------------------------------------

vim mysite_uwsgi.py

# mysite_uwsgi.py
import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application()

  

## ------------------------------------------------------------------------------------------------------------------------

vim mysite_uwsgi.ini

[uwsgi]
socket = :8001
master = true
module = mysite_uwsgi
processes = 8
listen = 120
enable-threads = true
daemonize = /path/to/your/project/base/mysite/mysite_uwsgi.log
pidfile = /path/to/your/project/base/mysite/mysite_uwsgi.pid
pythonpath = /path/to/your/project/base/mysite/
pythonpath = /path/to/your/project/base/mysite/mysite_uwsgi
pythonpath = /path/to/your/project/base/mysite/mysite
buffer-size = 32768
reload-mercy = 8
vacuum = true

After all of these above,we can go to Step 3.

 

Step 3:Restart Your Nginx Service And uWsgi service

Here list the Commonly used commands:
sudo /etc/init.d/nginx stop

sudo /etc/init.d/nginx start

sudo /etc/init.d/nginx restart

And in this step you just need to restart your nginx(if it is started before, or use start instead)

 

sudo /etc/init.d/nginx restart # restart nginx

chdir /path/to/your/project/base/mysite

uwsgi --socket 127.0.0.1:8001 --wsgi-file mysite_uwsgi.py # start uwsig service,if not,you will get a 502(Bad Gateway) error.

 

Tips:

  chdir /path/to/your/project/base/mysite

  uwsgi --http 10.10.10.132:8001 --wsgi-file mysite_uwsgi.py

  and then type http://10.10.10.132:8000/ in your browser to see if uwsgi work ok.if ok ,then shose socket

 

Tips:

  nginx + uwsgi

  apache + mod_wsgi

  nginx + apache + ???

 

 Step 4:Check If It is OK

Open your browser and type http://10.10.10.132:8000/ (10.10.10.132:8000 also ok)

And you will see the django‘s beautiful welcome page.

bubuko.com,布布扣

 

for more information:

tutorial from uwsgi.readthedocs.org:Django_and_nginx (follow it but failed,orz...)

tutorial from oschina.net:nginx + uwsgi + django (work)

Start Your Django Project in Nginx with uWsgi

标签:style   blog   http   color   io   os   ar   strong   for   

原文地址:http://www.cnblogs.com/MrWho/p/start-your-django-project-in-nginx-with-uwsgi.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!