ngix uwsgi django combination website building
Since I recently had to do an innovative project that required python web development, I studied django, a very versatile python web framework.
Why do you need ngix?
First of all, let’s talk about why it is necessary to combine these three to build a website. If you only use Django, you cannot achieve load balancing. For example, if you need to request some static resources, you need Django to process them all, and the requests cannot be distributed reasonably, and ngix It can just solve this problem (it seems that this project does not need to consider load balancing~~ but improving performance is always necessary). ngix can send some dynamic requests to django for processing through configuration, and handle static requests by itself. In addition, if you still need to run PHP pages on the website, then ngix is definitely a good choice. It distributes PHP requests to apache for processing. ngix and apache communicate through the socket port, and then return the processed results to the client.
Then why do you need uwsgi?
WSGI is a web server gateway interface. It is a specification for communication between a web server (such as nginx) and an application server (such as uWSGI server). Then uwsgi is a web server that implements both uwsgi and WSGI protocols. To put it simply, using uwsgi we can start django from uwsgi, and then ngix communicates with uwsgi through the port. In this process, gjango realizes the function of wsgi server, and ngix realizes the function of wsgi client, but in the web, ngix plays the role of a server (Many software communications in computers are in client-server mode. For example, file resources are a service, and then the application implements the corresponding protocol to call this service). This realizes the transfer of uwsgi between ngix and django.
Why not let ngix communicate with django directly?
uWSGI does not use either the wsgi protocol or the fcgi protocol. Instead, it creates its own uwsgi protocol, which is said to be about 10 times faster than the fcgi protocol.
The main features of uWSGI are as follows:
◆Ultra-fast performance.
◆Low memory usage (measured to be about half of apache2’s mod_wsgi).
◆Multiple app management.
◆Detailed log function (can be used to analyze app performance and bottlenecks).
◆Highly customizable (memory size limit, restart after a certain number of services, etc.).
The principles between the three are as follows,
<span><code>the web client <-> the web server(nginx) <-> the socket <-> uwsgi <-> Django</code></span>
Start deployment
1. Install ngix sudo apt-get install ngix
Thanks to my machine There is also apache on it. I need to modify the listening port of ngix to 8080
The modification is as follows
server { listen 8080 default_server; listen [::]:8080 default_server ipv6 root /var/ngix; #将根目录改为/var/ngix index index.html index.htm; }
2. Install django
Use python’s own package manager easy_install to installeasy_install django Automatically install the latest version
3. Install uwsgi
<code>apt-get install python-dev #不安装这个,下面的安装可能会失败 pip install uwsgi 如果是apt-get安装就需要 sudo apt-get install uwsgi-plugin-python </code>
.
└── myproject
├── app
│ ├── admin.py
│ ├── __init__.py
│ ├─ migration─s
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── db.sqlite3
├ ── manage.py
├── myproject
│ ├── django.xml
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── settings.py
│ ├── settings .pyc
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi.py
│ └── wsgi.pyc
├── templates
└── test.py
django.xml file content is:
<uwsgi> <socket>127.0.0.1:8630</socket> <chdir>/var/ngix/myproject/myproject</chdir> <pythonpath>..</pythonpath> <module>wsgi</module> </uwsgi> 这里需要注意的是wsgi模块,网上很多都是错误的,直接用自动生成的就行。
Then you need to add it to the ngix configuration file
location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8630; }
Restart the ngix service, and then start the uwsgi service
$ uwsgi -x django.xml --plugin python
needs to be executed in the directory where django. Got it~~
After a day of tossing, it’s done
Let’s summarize other things learned: deleting the corresponding installation files under /etc/dpkg/info/ can solve the problem of apt sub-process startup errors. After deleting it, you need to autoremove it
Finally, distribution is really a big pitfall! ! ! ! ! ! ! !
Data sharing: wsgi concept uwsgi concept Deploying Django on Ubuntu based on nginx and uWSGI
How to hand over uwsgi to supervisor management unavailable-modifier-requested-0 solution
uwsgi manual
Summary of frequently asked questions about deploying django with uwsgi
Django Chinese tutorial It is recommended to read the English tutorial, which is more complete
The above is the information I refer to
The above introduces the ngix uwsgi django combination website building, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Steps to check the Django version: 1. Open a terminal or command prompt window; 2. Make sure Django has been installed. If Django is not installed, you can use the package management tool to install it and enter the pip install django command; 3. After the installation is complete , you can use python -m django --version to check the Django version.

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

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 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 check the django version: 1. To check through the command line, enter the "python -m django --version" command in the terminal or command line window; 2. To check in the Python interactive environment, enter "import django print(django. get_version())" code; 3. Check the settings file of the Django project and find a list named INSTALLED_APPS, which contains installed application information.
