**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.
Configuration file: /etc/nginx
Program: /usr/sbin/nginx
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