Deploy a Django project under Ubuntu

Source: Internet
Author: User

Django is a Python open-source web framework, and Django itself is also a lightweight server that can meet local testing, extensive access in production environments, and a combination of Nginx and Apache. The following is a case of Django and Nginx deployment


1. Deployment environment


Operating system: Ubuntu 16.04.2


Nginx Version: nginx/1.10.3


2. Principle of deployment

Client----"Nginx----" socket----"UWSGI----" Django



3. Installation Steps


3.1 Installing Nginx


Apt-get Install Nginx


Systemctl start Nginx


Test Nginx


3.2 Installing Uwsgi


Pip Install Uwsgi


Create test.py test Uwsgi under opt to install properly

#!/usr/bin/env pythondef Application (env,start_response): Start_response (' K OK ', [(' Content-type ', ' text/html ')]) r Eturn ["Hello World"]


Test:

Uwsgi--http:8000--wsgi-file test.py


Access to IP:8000,UWSGI Test succeeded




3.3 Nginx+uwsgi+django


Uploading a Django project to Ourcmdb


Create a Ourcmdb_uwsgi.ini configuration file

#OurCMDB_uwsgi .ini[uwsgi]# django-related settingssocket = :8000 # socket  Listening port, corresponding to the port number of nginx  configuration file  uwsgi_pass  listener # the base directory  (Full path) chdir           = /opt/ourcmdb/      #项目目录 # django s wsgi filemodule           = OurCMDB.wsgi     #wsgi .py  Create a django  project when you have generated   catalog  /opt/ ourcmdb/ourcmdb/wsgi.py# process-related settings# mastermaster           = true# maximum number of worker  processesprocesses       = 4  ## ... with  appropriate permissions - may be needed# chmod-socket    =  664# clear environment  on exitvacuum          = true 


View the files under the project



New Nginx Virtual configuration file

Cat/etc/nginx/sites-available/ourcmdb_nginx.conf

server {    listen         8010;      server_name    _;    charset UTF-8;     access_log      /var/log/nginx/OurCMDB_access.log;     error_log       /var/log/nginx/OurCMDB_error.log;     client_max_body_size 75M;    location / {          include uwsgi_params;         uwsgi_pass 127.0.0.1:8000; #        uwsgi_read_timeout  2;    }       location /static {         expires 30d;        autoindex  on;         add_header cache-control private;         alias /opt/ourcmdb/static/;      } }

Create soft Connect ln-s ourcmdb_nginx.conf. /sites-enabled/ourcmdb_nginx.conf


Start

Uwsgi--ini Ourcmdb_uwsgi.ini


Check nginx configuration file


Start Nginx


Access Test Django


http://ip:8010/



Deploy a Django project under Ubuntu

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.