How to deploy Django on Ubuntu 14.04

**first step. **

sudo apt-get update

sudo apt-get upgrade

Update first. .

Django's mainstream deployment method: nginx+uwsgi+django

The second step is to install nginx

sudo apt-get install nginx

Install nginx, if you need to install the latest nginx, you need to download the source package from the official website for manual compilation.

The general file structure of nginx.

  1. Configuration file: /etc/nginx

  2. Program: /usr/sbin/nginx

  3. Log: /var/log/nginx/access.log – error.log

The third step is to install uwsgi

sudo apt-get install python3-dev

sudo apt-get install python3-pip

sudo pip3 install uwsgi (before this step, you can change the pip source to increase the download speed. Create pip.conf under ~/.pip to write

[ global]

trusted-host = pypi.douban.com

index-url = http://pypi.douban.com/simple)

uwsgi is a web server that implements WSGI, uwsgi, http and other protocols. The function of HttpUwsgiModule in Nginx is to exchange with uWSGI server.

The general process is: Client<==>nginx<==>uwsgi<==>Django. Static requests are handled by Nginx itself. Non-static requests are passed to Django through uwsgi and processed by Django to complete a WEB request.

Create a Django test project, django-admin startproject mysite, cd mysite, python manage.py startapp demo1.

The fourth step is to test uwsgi

Create a new test file in the mysite directory, nano test.py.

Write:

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

run:

uwsgi --http :8001--plugin python --wsgi-file test.py

Access is normal.

The fifth step, test Django

python manage.py runserver 0.0.0.0:8002

Access is normal.

Connect Django and uwsgi.

uwsgi --http:8001--plugin python --module mysite.wsgi

Access is normal.

The sixth step, configure uwsgi

uwsgi supports startup through a variety of configuration files, here the ini configuration file method is used.

New uwsgi: nano uwsgi.ini

# mysite_uwsgi.ini file
 [ uwsgi]

 socket =127.0.0.1:3400
 # Django-related settings
 # the django project directory(full path)
 chdir      =/home/ubuntu/mysite
 # Django's wsgi file
 module     = mysite.wsgi

 # process-related settings
 # master
 master     =true
 # maximum number of worker processes
 processes    =2

 threads =2
 max-requests =6000

 # ... with appropriate permissions - may be needed
 chmod-socket  =664
 # clear environment on exit
 vacuum     =true

An error was reported during access, invalid request block size: 21573 (max 4096)...skip.

The reason is that the url address exceeds 4096 characters, and the reason is that we start it in a socket mode. You can change the socket of the configuration file to http or modify the buffer-size.

( It is recommended not to modify, just change to http during testing, and change back to socket when connecting to nginx)

daemonize =/home/ubuntu/mysite/uwsgi.log

Add this code to the uwsgi.ini file during the formal operation, and the access log will be output to uwsgi.log in the background

At this point django has been able to access.

The seventh step is to configure nginx

Modify nginx's default configuration file /etc/nginx/sites-enabled/default

server {
 # the port your site will be served on
 listen   80;
 # the domain name it will serve for
 server_name 127.0.0.1; # substitute your machine's IP address or FQDN
 charset   utf-8;

 # max upload size
 client_max_body_size 75M;  # adjust to taste

 # Django media
 location /media {
 alias /home/ubuntu/mysite/media; # your Django project's media files - amend as required
  }

 location /static{
 alias /home/ubuntu/mysite/static; # your Django project's static files - amend as required
  }

 # Finally, send all non-media requests to the Django server.
 location /{
 include   uwsgi_params; # the uwsgi_params file you installed
 uwsgi_pass 127.0.0.1:8001;#This is consistent with the uwsgi configuration file
  }}

Remember to modify the configuration of uwsgi.ini during the test.

The eighth step, run

Restart nginx and run uwsgi.

You're done

The above Django deployment method on Ubuntu 14.04 is all the content shared by the editor. I hope to give you a reference.

Recommended Posts

How to deploy Django on Ubuntu 14.04
How to quickly deploy docker on ubuntu server
How to install Django Web Framework on Ubuntu 18.04
How to deploy Clojure web application on Ubuntu 14.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to upgrade to PHP 7 on Ubuntu 14.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Jenkins on Ubuntu 18.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to secure Nginx on Ubuntu 14.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to uninstall software on Ubuntu
How to install Nginx on Ubuntu 16.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
How to add swap space on Ubuntu 20.04
How to install Docker Compose on Ubuntu 18.04
How to install Ubuntu on Raspberry Pi
How to set up Gogs on Ubuntu 14.04
How to secure Redis installation on Ubuntu 14.04
How to build nfs service on ubuntu16.04