Nginx+uwsgi Production Deployment Django

Source: Internet
Author: User
Tags call back

The process of deployment is simple, the core of deployment is why to do so, each parameter represents what meaning, the ultimate goal is to understand, some basic conceptual things.

UWSGI Introduction

Before you say Uwsgi, talk about Wsgi first.

What is WSGI?

WSGI: is a Web server gateway interface that is a specification for a Web server (such as Nginx) to communicate with an application server, such as a UWSGI server.

UWSGI is a Web server, it implements the WSGI protocol, Uwsgi,http and other protocols, Nginx Httpuwsgimodul function is to exchange with the UWSGI server

What about the frameworks that bring WSGI server?

Many frameworks have their own WSGI servers, such as Flask, Webpy, Dajngo, CherryPy, and so on. Of course, the performance is not good, the self-brought Web server is more local testing purposes, the release of the use of the production environment of the WSGI server or the joint nginx do UWSGI.

In simple terms, WSGI is the standard,

For example: A German chatting with a Frenchman who wants to chat can interact through a standard international language: English.

Be aware of the distinction between the three concepts of WSGI/UWSGI/UWSGI.

WSGI is a communication protocol

UWSGI is a communication protocol like WSGI.

UWSGI is a Web server that implements the two Protocols of Uwsgi and WSGI.

Why Uwsgi also need nginx, should be for Nginx has excellent static content processing ability, and then transfer the dynamic content to the UWSGI server, so that the realization, static and dynamic separation. can also be better to achieve the client's effect.

Common Python http Server

The early web Server

Early in the day, only the static content, at that time, web development is very simple, the development of this often to operate the Web server, and write some HTML pages into the server-specified folder (WWW), these HTML pages are used when the browser requests the page,

With the development of time, the problem arises, you can only get static content, if you want visitors to see how many other visitors visited the site, or want to let visitors submit some of the mailbox name, address of the form, this is more troublesome.

Mid-webserver

In the middle, you can access some dynamic data, when the browser access to webserver, you can call back some data in the background, write small programs, a lot of people, all kinds of people have, and then unified a standard, CGI, with the evolution of time, to 05 years or so, into the Web application era,

The Web Server now

Actual deployment process

Installing Nginx

Yum Install Nginx

Install UWSGI after Nginx installation is complete.

Pip Install Uwsgi

After the above two installations are complete, now start configuring Uwsgi, go to the project root directory, note: The project should not be placed in the root directory.

Execute a command to test whether the project can be started by Uwsgi.

Uwsgi--http 192.168.31.123:80--file teacher/wsgi.py--static-map=/static=static192.168.31.123: Your IP address

After successful startup

After entering the project and directory, create an empty folder in the sibling directory:

mkdir Script

After the creation is complete, create the Uwsgi.ini file in the directory.

Vim Uwsgi.ini

After the INI file is created, put the contents into the folder.

   [Uwsgi]   # project Directory    chdir=/opt/project_teacher/teacher/    # start UWSGI user name and user group    uid=root    gid=root    # Specifies the application Module=teacher.wsgi:application # of the project to    Specify the sock file path    socket=/opt/project_teacher/script/ Uwsgi.sock      # Sock file is automatically generated after the Uwsgi.ini file is started    # Enable main process    Master=true    # Number of processes    workers=5    Pidfile=/opt/project_teacher/script/uwsgi.pid    # automatically removes UNIX sockets and PID files when the service stops    vacuum=true    # Serialization of accepted content, if possible    thunder-lock=true    # Enable thread    enable-threads=true    # Set self-interrupt time    harakiri=30    # Set Buffer    post-buffering=4096    # Set log directory    Daemonize=/opt/project_teacher/script/uwsgi.log

When the above configuration is complete, start the Uwsgi.ini file and review the process.

Uwsgi end, so congratulations, UWSGI has been configured to complete, now start configuring Nginx, go to the following directory to modify the default.conf file:

Cd/etc/nginx/conf.d/vim default.conf

After entering the file, say, code, close to the file:

    server {Listen 80;       server_name 10.129.205.183;                    # domain name Access_log/var/log/nginx/access.log main;                    CharSet Utf-8;                    gzip on; Gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text                    /json image/jpeg image/gif image/png application/octet-stream;                    Error_page 404/404.html;                    Error_page 502 503 504/50x.html;                        # Specify Project path UWSGI location/{include uwsgi_params;                        Uwsgi_connect_timeout 30;                    Uwsgi_pass Unix:/opt/project_teacher/script/uwsgi.sock; } # Specifies the static file path location/static/{alias/opt/project_teacher/                        teacher/static/;         Index index.html index.htm;           }    } 

Start Ngxin

After you start Nginx, when you start Uwsgi, you open the browser, enter the server_name you set, is not able to access your project,

Project, recently I want to build their own a simple blog, the basic page, and the function has been completed, the latter will add some, advanced a bit of things, after all, now there is no me, blog as follows:

Upload blog content, is integrated Baidu, Ueditor, before the Django Admin to integrate the Django-ueditor, think about, or write a place to add articles.

Git Source Address:

Github.com/mrwyc/djangoblog

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.