Home Backend Development Python Tutorial Introduction to deployment examples of Ubuntu14.04

Introduction to deployment examples of Ubuntu14.04

Jul 23, 2017 pm 01:37 PM
django deploy

first step.

sudo apt-get update

sudo apt-get upgrade

Update first. .

The mainstream deployment method of Django: 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 code package from the official website and compile it manually.

The approximate 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, 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 improve the download speed. Create pip.conf under ~/.pip and write

[global]

trusted-host = pypi.douban.com

index-url = )

uwsgi is a web server that implements the WSGI protocol, uwsgi, http Waiting for agreement. 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, 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.

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"]
Copy after login

Run:

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

Access is normal.

The fifth step is to test that Django

python manage.py runserver 0.0.0.0:8002
Copy after login

has normal access.

Connect Django and uwsgi.

uwsgi --http:8001 --plugin python --module mysite.wsgi
Copy after login

Access is normal.

The sixth step is to configure uwsgi

uwsgi supports starting through a variety of configuration files. The ini configuration file method is used here.

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 filemodule          = mysite.wsgi

    # process-related settings
    # master
    master          = true# maximum number of worker processes
    processes       = 2threads = 2max-requests = 6000# ... with appropriate permissions - may be neededchmod-socket    = 664# clear environment on exit
    vacuum          = true
Copy after login

An error occurred when accessing, invalid request block <span class="hljs-built_in">size: <span class="hljs-number">21573 (<span class="hljs-built_in">max <span class="hljs-number">4096)...skip</span></span></span></span>.

The reason is that the url address exceeds 4096 characters. The reason is that we use socket to start. Just change the socket in the configuration file to http, or modify the buffer-size.

(It is recommended not to make any changes, just change it to http during testing, and change it back to socket when connecting to nginx)

daemonize = /home/ubuntu/mysite/uwsgi.log
Copy after login

Replace this code when it is officially run Add it to the uwsgi.ini file, and the access log will be output to uwsgi.log in the background

At this time, Django can already access it.

Step 7, 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 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/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;#此处跟uwsgi配置文件保持一致
    }
}
Copy after login

Remember to modify the uwsgi.ini configuration during testing.

Step 8, run

Restart nginx, run uwsgi.

Done

This is it for the time being, we will continue to add knowledge about nginx, django, and uwsgi in the future .

Most of the configurations come from Baidu search, so I won’t post each source one by one. Life is too short.

The above is the detailed content of Introduction to deployment examples of Ubuntu14.04. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Django vs. Flask: A comparative analysis of Python web frameworks Django vs. Flask: A comparative analysis of Python web frameworks Jan 19, 2024 am 08:36 AM

Django and Flask are both leaders in Python Web frameworks, and they both have their own advantages and applicable scenarios. This article will conduct a comparative analysis of these two frameworks and provide specific code examples. Development Introduction Django is a full-featured Web framework, its main purpose is to quickly develop complex Web applications. Django provides many built-in functions, such as ORM (Object Relational Mapping), forms, authentication, management backend, etc. These features allow Django to handle large

Django Framework Pros and Cons: Everything You Need to Know Django Framework Pros and Cons: Everything You Need to Know Jan 19, 2024 am 09:09 AM

Django is a complete development framework that covers all aspects of the web development life cycle. Currently, this framework is one of the most popular web frameworks worldwide. If you plan to use Django to build your own web applications, then you need to understand the advantages and disadvantages of the Django framework. Here's everything you need to know, including specific code examples. Django advantages: 1. Rapid development-Djang can quickly develop web applications. It provides a rich library and internal

How to upgrade Django version: steps and considerations How to upgrade Django version: steps and considerations Jan 19, 2024 am 10:16 AM

How to upgrade Django version: steps and considerations, specific code examples required Introduction: Django is a powerful Python Web framework that is continuously updated and upgraded to provide better performance and more features. However, for developers using older versions of Django, upgrading Django may face some challenges. This article will introduce the steps and precautions on how to upgrade the Django version, and provide specific code examples. 1. Back up project files before upgrading Djan

Yolov10: Detailed explanation, deployment and application all in one place! Yolov10: Detailed explanation, deployment and application all in one place! Jun 07, 2024 pm 12:05 PM

1. Introduction Over the past few years, YOLOs have become the dominant paradigm in the field of real-time object detection due to its effective balance between computational cost and detection performance. Researchers have explored YOLO's architectural design, optimization goals, data expansion strategies, etc., and have made significant progress. At the same time, relying on non-maximum suppression (NMS) for post-processing hinders end-to-end deployment of YOLO and adversely affects inference latency. In YOLOs, the design of various components lacks comprehensive and thorough inspection, resulting in significant computational redundancy and limiting the capabilities of the model. It offers suboptimal efficiency, and relatively large potential for performance improvement. In this work, the goal is to further improve the performance efficiency boundary of YOLO from both post-processing and model architecture. to this end

How to solve the problem of inaccessibility after Tomcat deploys war package How to solve the problem of inaccessibility after Tomcat deploys war package Jan 13, 2024 pm 12:07 PM

How to solve the problem that Tomcat cannot successfully access the war package after deploying it requires specific code examples. As a widely used Java Web server, Tomcat allows developers to package their own developed Web applications into war files for deployment. However, sometimes we may encounter the problem of being unable to successfully access the war package after deploying it. This may be caused by incorrect configuration or other reasons. In this article, we'll provide some concrete code examples that address this dilemma. 1. Check Tomcat service

Gunicorn Deployment Guide for Flask Applications Gunicorn Deployment Guide for Flask Applications Jan 17, 2024 am 08:13 AM

How to deploy Flask application using Gunicorn? Flask is a lightweight Python Web framework that is widely used to develop various types of Web applications. Gunicorn (GreenUnicorn) is a Python-based HTTP server used to run WSGI (WebServerGatewayInterface) applications. This article will introduce how to use Gunicorn to deploy Flask applications, with

Is Django front-end or back-end? check it out! Is Django front-end or back-end? check it out! Jan 19, 2024 am 08:37 AM

Django is a web application framework written in Python that emphasizes rapid development and clean methods. Although Django is a web framework, to answer the question whether Django is a front-end or a back-end, you need to have a deep understanding of the concepts of front-end and back-end. The front end refers to the interface that users directly interact with, and the back end refers to server-side programs. They interact with data through the HTTP protocol. When the front-end and back-end are separated, the front-end and back-end programs can be developed independently to implement business logic and interactive effects respectively, and data exchange.

How to use the Django framework to create a project in PyCharm How to use the Django framework to create a project in PyCharm Feb 19, 2024 am 08:56 AM

Tips on how to create projects using the Django framework in PyCharm, requiring specific code examples. Django is a powerful Python Web framework that provides a series of tools and functions for quickly developing Web applications. PyCharm is an integrated development environment (IDE) developed in Python, which provides a series of convenient functions and tools to increase development efficiency. Combining Django and PyCharm makes it faster and more convenient to create projects

See all articles