Start your Django project in nginx with uwsgi

Source: Internet
Author: User

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 embedded 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!

# Renewal ##------------------------------------------------------------------------------------------------------------------------

Vim mysite_uwsgi.conf

# mysite_uwsgi.confserver {    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 ')

# Renewal ##------------------------------------------------------------------------------------------------------------------------

Vim mysite_uwsgi.py

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

  

# Renewal ##------------------------------------------------------------------------------------------------------------------------

Vim mysite_uwsgi.ini

[uwsgi]socket = :8001master = truemodule = mysite_uwsgiprocesses = 8listen = 120enable-threads = truedaemonize = /path/to/your/project/base/mysite/mysite_uwsgi.logpidfile = /path/to/your/project/base/mysite/mysite_uwsgi.pidpythonpath = /path/to/your/project/base/mysite/pythonpath = /path/to/your/project/base/mysite/mysite_uwsgipythonpath = /path/to/your/project/base/mysite/mysitebuffer-size = 32768reload-mercy = 8vacuum = 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.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.

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.