Introduction to Ubuntu14.04 Deployment examples

Source: Internet
Author: User
The first step.


Digitalocean django nginx ubuntu 18



sudo apt-get update


Django ubuntu nginx 

sudo apt-get upgrade



Update First:



The main way to deploy Django: Nginx+uwsgi+django

502 bad gateway nginx 1.10 3 ubuntu django


Step two, install Nginx



sudo apt-get install Nginx



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



Nginx's approximate file structure.



1. configuration file:/etc/nginx



2. Procedure:/usr/sbin/nginx



3. LOG:/var/log/nginx/access.log-error.log






Step three, install Uwsgi



sudo apt-get install Python3-dev



sudo apt-get install Python3-pip



sudo pip3 install Uwsgi (before this step, you can replace the PIP source to increase the download speed.) Create a pip.conf write under ~/.pip



[Global]



Trusted-host = pypi.douban.com



Index-url =)






UWSGI is a Web server that implements protocols such as WSGI Protocol, UWSGI, HTTP, and so on. The role of Httpuwsgimodule in Nginx is to exchange with the UWSGI server.



The approximate process is: client <==>nginx<==>uwsgi<==>django. The static request is handled by Nginx itself. Non-static requests are passed through Uwsgi to Django, which is processed by Django to complete a Web request.






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












Fourth step, Test Uwsgi



Create a new test file under the MySite directory, nano test.py.



Write:


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


Run:


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


Access is normal.






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.






Sixth Step, configure Uwsgi



The UWSGI supports booting through a variety of configuration files, using the INI configuration file method.






New Uwsgi:nano Uwsgi.ini





# Mysite_uwsgi.ini FILE[UWSGI]    socket = 127.0.0.1:3400# django-related Settings    # The Django project directory (f ull path)    chdir           =/home/ubuntu/mysite    # Django ' s wsgi filemodule          = Mysite.wsgi    # process-related Settings    # Master    Master          = true# Maximum number of worker processes    processes       = 2threads = 2max-requests = 6000# ... with appropriate permissions-may is neededchmod-socket    = 664# clear Environment on exitvacuum          = True








Access times wrong,invalid request block size: 21573 (max 4096)...skip.



The reason is that the URL address is more than 4,096 characters, because we start with a socket, change the configuration file socket to HTTP, or modify the buffer-size.



(It is recommended not to make changes, the test is changed to HTTP, etc., when the connection Nginx, change back to the socket)


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


The formal runtime adds this code to the Uwsgi.ini file, and the access log is spooled to the Uwsgi.log



At this point Django has access to it.









Seventh Step, configure Nginx



Modify Nginx's default profile/etc/nginx/sites-enabled/default


server {    # The port your site is served on    listen      ;    # The domain name it would serve Forserver_name 127.0.0.1; # Substitute your machine ' s IP address or fqdncharset     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/stat Ic # 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;# Consistent with UWSGI configuration file here    }}


Remember to modify the configuration of the Uwsgi.ini when testing.



Eighth step, run



Restart Nginx and run Uwsgi.



Done



For the time being, follow-up continues to add Nginx, Django, Uwsgi knowledge.



Most of the configuration from Baidu Search, do not post each source. Life is short.


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.