Python-django NGINX+UWSGI Installation Configuration

Source: Internet
Author: User
Tags install django pip install django

Django NGINX+UWSGI Installation Configuration
In the previous chapters we used the Python manage.py runserver to run the server. This is used only in test environments.
Official release of the service, we need a stable and continuous server, such as Apache, Nginx, LIGHTTPD, etc., this article will take Nginx as an example.
--------------------------------------------------------------------------------
Install the basic development package
The installation steps under Centos are as follows:
Yum Groupinstall "Development tools"
Yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
CentOS comes with Python 2.4.3, but we can install Python2.7.5 again:
CD ~
wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2
Tar xvf python-2.7.5.tar.bz2
CD Python-2.7.5
./configure--prefix=/usr/local
Make && make Altinstall
Install Python package Management
Easy_install Bag Https://pypi.python.org/pypi/distribute
Installation steps:
CD ~
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz
Tar XF distribute-0.6.49.tar.gz
CD distribute-0.6.49
python2.7 setup.py Install
Easy_install--version
PIP Package: Https://pypi.python.org/pypi/pip
The advantage of installing PIP is that you can pip list, pip Uninstall Management Python package, Easy_install does not have this function, only uninstall.
https://pip.pypa.io/en/stable/installing/
wget https://bootstrap.pypa.io/get-pip.py
Python get-pip.py
--------------------------------------------------------------------------------
Installing UWSGI
Uwsgi:https://pypi.python.org/pypi/uwsgi
Uwsgi parameter explanation: http://uwsgi-docs.readthedocs.org/en/latest/Options.html
Pip Install Uwsgi
Download install if PIP installation fails: https://pypi.python.org/packages/bb/0a/ 45e5aa80dc135889594bb371c082d20fb7ee7303b174874c996888cc8511/uwsgi-2.0.15.tar.gz
TAR-ZXVF uwsgi-2.0.15.tar.gz
CD uwsgi-2.015
python2.7 setup.py Install

Uwsgi--version # View UWSGI version
Test whether the Uwsgi is normal:
Create a new test.py file with the following contents:
DEF application (env, Start_response):
Start_response (' K OK ', [(' Content-type ', ' text/html ')])
Return "Hello World"
Then run at the terminal:
Uwsgi--http:8001--wsgi-file test.py
Enter in the browser: http://127.0.0.1:8001, to see if there is "Hello world" output, if there is no output, please check your installation process.
--------------------------------------------------------------------------------
Installing Django
SOURCE Installation:
wget https://www.djangoproject.com/download/1.9.13/tarball/
python2.7 setup.py Install

PIP Installation: https://www.djangoproject.com/download/
Pip Install django==1.*
To test if Django is working, run:
django-admin.py Startproject Demosite
CD Demosite
python2.7 manage.py Runserver 0.0.0.0:8002
Enter: http://127.0.0.1:8002 in the browser to check if Django is working properly.
--------------------------------------------------------------------------------
Installing Nginx
The installation commands are as follows:
CD ~
wget http://nginx.org/download/nginx-1.5.6.tar.gz
Tar XF nginx-1.5.6.tar.gz
CD nginx-1.5.6
./configure--prefix=/usr/local/nginx-1.5.6 \
--with-http_stub_status_module \
--with-http_gzip_static_module
Make && make install
You can read the Nginx installation configuration for more information.
--------------------------------------------------------------------------------
UWSGI Configuration
Uwsgi support INI, XML and other configuration methods, in this paper, INI as an example, in the/ect/directory under the new Uwsgi9090.ini, add the following configuration:
[Uwsgi]
Socket = 127.0.0.1:9090
Master = TRUE//Master process
Vhost = TRUE//multi-station mode
No-site = TRUE//multi-station mode when no ingress modules and files are set
Workers = 2//number of child processes
Reload-mercy = 10
Vacuum = TRUE//exit, clean file on restart
max-requests = 1000
Limit-as = 512
Buffer-size = 30000
Pidfile =/var/run/uwsgi9090.pid//pid file for the following script to start, stop the process
Daemonize =/website/uwsgi9090.log

[Uwsgi]
Plugin = python, http
env = Django_production_settings=true

ChDir =/home/wwwdata/wiki

module = Zer0blog.wsgi

Master=true
processes = 4
HTTP =: 8091
Vaccum=true

Touch-reload =/home/wwwdata/wiki


--------------------------------------------------------------------------------
Nginx Configuration
Locate the Nginx installation directory (for example:/usr/local/nginx/), open the conf/nginx.conf file, and modify the server configuration:
server {
Listen 80;
server_name localhost;

Location/{
Include Uwsgi_params;
Uwsgi_pass 127.0.0.1:9090; Must be consistent with the settings in Uwsgi
Uwsgi_param Uwsgi_script Demosite.wsgi; The portal file, the location of the wsgi.py relative to the project root directory, "." Equivalent to one level of directory
Uwsgi_param Uwsgi_chdir/demosite; Project root directory
Index index.html index.htm;
Client_max_body_size 35m;
}
}

You can read the Nginx installation configuration for more information.
After Setup is complete, run at Terminal:
Uwsgi--ini/etc/uwsgi9090.ini &
/usr/local/nginx/sbin/nginx
In the browser input: http://127.0.0.1, you can see Django's "It work".

Installing the PIL Graphics library
Pip Install Pillow
Installing tagging
Pip Install django-tagging

Python-django NGINX+UWSGI Installation Configuration

Related Article

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.