home PYTHONJAVA
 

Django Nginx+uwsgi installation configuration

In the previous section we used python manage.py runserver to run the server. This only applies to use in a test environment.

For the officially released service, we need a server that can be stable and continuous, such as apache, Nginx, lighttpd, etc. This article will take Nginx as an example.


Installing the basic development kit

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 Python 2.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< Span class="pln">
Make && make altinstall

Install Python package management

easy_install package 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 manage Python packages with pip list and pip uninstall. easy_install does not have this feature, only uninstall.


Install uwsgi

uwsgi:https://pypi.python.org/pypi/uWSGI

The uwsgi parameter details: http://uwsgi-docs.readthedocs.org/en/latest/Options .html

pip install uwsgi
Uwsgi --version # view uwsgi version

Test if uwsgi is normal:

Create a new test.py file with the following contents:

def application(env, start_response) :
    start_response('200 OK' , [('Content-Type','text/html')])
    return "Hello World"< /span>

Then run at the terminal:

uwsgi --http < /span>:8001 - -wsgi-file test.py

Enter http://127.0.0.1:8001 in the browser to see if there is "Hello World" output. If there is no output, please check your installation process.


Install Django

pip install django

Test if django is working properly, run:

django-admin.py startproject demosite
Cd demosite
Python2.7 manage.py runserver 0.0.0.0:8002

In the browser, type: http://127.0.0.1:8002, check if django is working properly.


Install Nginx

The installation command is 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< Span class="pun">/nginx-1.5.6 \
--with-http_stub_status_module \
--with-http_gzip_static_module
Make && make install
uwsgi --http < /span>:8001 - -wsgi-file test.py

Enter http://127.0.0.1:8001 in the browser to see if there is "Hello World" output. If there is no output, please check your installation process.


Install Django

pip install django

Test if django is working properly, run:

django-admin.py startproject demosite Cd demosite Python2.7 manage.py runserver 0.0.0.0:8002

In the browser, type: http://127.0.0.1:8002, check if django is working properly.


Install Nginx

The installation command is 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< Span class="pun">/nginx-1.5.6 \ --with-http_stub_status_module \ --with-http_gzip_static_module Make && make install
......

After the setup is complete, run in the terminal:

uwsgi --ini < /span>/etc/ Uwsgi9090.ini &
/usr/local/nginx/sbin/nginx

In the browser input: http://127.0.0.1, you can see django's "It work".






welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.