Deployment of Nginx + uWSGI + Django + Python application architecture

Source: Internet
Author: User
Tags install django python mysql django tutorial

Deployment of Nginx + uWSGI + Django + Python application architecture

The CentOS 6.5 System

1. install and configure nginx and Python

Yum install nginx

Python is installed on 2.6 by default. Upgrade to 2.7. See the tutorial.

2. Install django

Download the latest version: Django-1.8.5.tar.gz

$ Wget -- no-check-certificate https://www.djangoproject.com/download/Django-1.8.5.tar.gz
(Note: -- no-check-certificate-free authentication; otherwise, https resources cannot be downloaded)
$ Tar zxf Django-1.8.5.tar.gz
$ Django-1.8.5 cd
$ Python setup. py install
[Root @ LinuxOT-Test-02 dj17] # python Python 2.7.3 (default, Jan 5 2013, 10:09:00) [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2Type "help ", "copyright", "credits" or "license" for more information. >>> import django> django. VERSION (1, 8, 5, 'final', 0)

It indicates that django is successfully installed.

3. Create a django Project

[Root @ LinuxOT-Test-02 nginx] # mkdir www
[Root @ LinuxOT-Test-02 nginx] # cd www
[Root @ LinuxOT-Test-02 www] # django-admin startproject mysite
[Root @ LinuxOT-Test-02 www] # tree mysite
/Mysite/
── Manage. py
── Mysite
── _ Init _. py
── Settings. py
── Urls. py
── Wsgi. py1
Directory, 5 files
[Root @ LinuxOT-Test-02 www] # cd mysite/
[Root @ LinuxOT-Test-02 mysite] # python manage. py runserver
Padding system checks...
System check identified no issues (0 silenced ).
You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage. py migrate' to apply them.
October 13,201 5-09:50:28
Django version 1.8.5, using settings 'mysite. setting' Starting development server
Quit the server with CONTROL-C.
[Root @ LinuxOT-Test-02 mysite] # python manage. py migrate
Operations to perform: Synchronize unmigrated apps: staticfiles, messages
Apply all migrations: admin, contenttypes, auth, sessionsSynchronizing apps without migrations: Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations: Rendering model states... DONE
Applying contenttypes.0001 _ initial... OK
Applying auth.0001 _ initial... OK
Applying admin.0001 _ initial... OK
Applying contenttypes.0002 _ remove_content_type_name... OK
Applying auth.0002 _ alter_permission_name_max_length... OK
Applying auth.0003 _ alter_user_email_max_length... OK
Applying auth.0004 _ alter_user_username_opts... OK
Applying auth.0005 _ alter_user_last_login_null... OK
Applying auth.0006 _ require_contenttypes_0002... OK
Applying sessions.0001 _ initial... OK
[Root @ LinuxOT-Test-02 mysite] # python manage. py runserver
Padding system checks...
System check identified no issues (0 silenced ).
October 13,201 5-09: 51: 25 Django version 1.8.5, using settings 'mysite. setting' Starting development server
Quit the server with CONTROL-C.
[Root @ LinuxOT-Test-02 dj17] # curl http: // 127.0.0.1: 8000

Normal response

4. Install uwsgi

Http://uwsgi-docs.readthedocs.org/en/latest/Download.html

[
Root @ LinuxOT-Test-02
Dj17] # wget
Http://projects.unbit.it/downloads/uwsgi-2.0.11.2.tar.gz

Support for Python/wsgi.

Install uwsgi Module

[Root @ LinuxOT-Test-02 mysite] # pip install uwsgi
Collecting uwsgi/usr/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg/pip/_ vendor/requests/packages/urllib3/util/ssl _. py: 90: InsecurePlatformWarning: A true SSLContext object is not available. this prevents urllib3 from signing SSL appropriately and may cause certain SSL connections to fail. for more information, see insecureplatformwarning.
InsecurePlatformWarning
Downloading uwsgi-2.0.11.2.tar.gz (782kB)
100% | too many threads have been transferred too many times | 782kB 413kB/s Installing collected packages: uwsgi
Running setup. py install for uwsgi
Successfully installed uwsgi-2.0.11.2
[Root @ LinuxOT-Test-02 mysite] # pip install
Collecting http://projects.unbit.it/downloads/uwsgi-lts.tar.gz
Downloading http://projects.unbit.it/downloads/uwsgi-lts.tar.gz (782kB)
100% | maximum number of rows between two rows was reduced. Maximum number of rows between two rows was reduced. Maximum number of rows between two rows was increased. Maximum number of rows between two rows was decreased. | 782kB 22kB/s
Requirement already satisfied (use -- upgrade to upgrade): uWSGI = 2.0.11.2 from http://projects.unbit.it/downloads/uwsgi-lts.tar.gz in/usr/lib/python2.7/site-packages
 
Yum install python-devel2.7
[Root @ LinuxOT-Test-02. test] # tar zxf uwsgi-2.0.11.2.tar.gz
[Root @ LinuxOT-Test-02. test] # cd uwsgi-2.0.11.2
[Root @ LinuxOT-Test-02] # python uwsgiconfig. py -- build
[Root @ LinuxOT-Test-02 uwsgi-2.0.11.2] # uwsgi -- version2.0.11.2
[Root @ LinuxOT-Test-02 uwsgi-2.0.11.2] # cp uwsgi/usr/sbin/uwsgi

5. Associate django with nginx

Vim/etc/nginx/conf. d/default. conf
Server {
Listen 80 default_server;
Server_name _;
Location /{
Include uwsgi_params;
Uwsgi_pass 127.0.0.1: 9090;
}
}
[Root @ LinuxOT-Test-02] # service nginx restart
Stop nginx: [OK]
Starting nginx: [OK]
[Root @ LinuxOT-Test-02 mysite] # uwsgi-s 127.0.0.1: 9090-w demo

Start the project

Access the nginx address.

How to Use Docker components to develop a Django project?

Install Nginx + uWSGI + Django on Ubuntu Server 12.04

Deployment of Django + Nginx + uWSGI

Django tutorial

Build a Django Python MySQL Linux development environment

Django details: click here
Django's: click here

This article permanently updates the link address:

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.