The environment
- MacBookAir
- Aliyun ESC: Centos7.0
- Nginx + 1.16.1
- Uwsgi = 2.0.18
- Django = 2.2.7
The server
- Enter aliyun website to register an account for purchase, select the region and server system configuration
- Add the security group after the purchase is successful (set up the accessible port, do not know how to set up, the website has documentation, here does not need to repeat)
- After the successful purchase has created an instance, click remote connection will have a password (do not remember can restart the instance to set) their own local documentation
- After entering the remote connection screen, use root+ login password (which I obtained by resetting the instance password) to connect
Remotely connect to server tools
- I use fianlshell
- The installation
cdDir (enter your installation directory) curl - o finalshell_install. Sh www.hostbuf.com/downloads/finalshell_install.sh; chmod +x finalshell_install.sh; sudo ./finalshell_install.shCopy the code
-
The connection
-
Complete the connection and configure the environment
Environment configuration
- Yum install libffi -devel-y (错 误 : ModuleNotFoundError: ModuleNotFoundError: No module named ‘_ctypes’)
- Use of PIP3:
- Since PYTHon3 is already installed and PIp3 already exists in the python3 installation directory, many installation packages must be installed using PIp3; Centos installed in PIP python2 we need to build soft connection (ln -s/usr/local/python3 / bin/pip3 / usr/bin/pip3)
- Mysql installation
Download the source mysql installation package: wget installed mysql source: http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm # yum install mysql57-community-release-el7-8.noarch. RPM # yum install mysql57-community-release-el7-8.noarch. RPM # yum install mysql57-community-release-el7-8.noarch. RPM Pip3 install mysqlclient: systemctl start mysqld: pip3 install mysqlclient: systemctl start mysqld Systemctl status mysqld: systemctlenableMysqld Change the root local login password: obtain the password: grep'temporary password' /var/log/mysqld.log enter mysql: mysql-uroot -pset password for 'root'@'localhost'=password('Your database password');
Copy the code
* During the installation process, there may be a failure to reset the password. My implementation is as follows: 1. 2. Reset the password (if the password does not exist, use authentication_string instead); Update the reset list to "FLUSH PRIVILEGES". 5. Enter mysql -u root -p. Password login;Copy the code
Django installation
- Run pip3 install Django
- Run django-admin help to verify that the installation is successful
Uwsgi installation
- Run pip3 install uwsgi
- Validation: UWSGi –version
- Note: if there is an error need to build a soft connection: ln -s/usr/local/python3 / bin/uwsgi/usr/bin/uwsgi
Nginx installation
- Run: yum install nginx
- Validation: nginx-v
- Note: error may occur with yum installation, this is because python3 is installed, so you need to modify the file content.
Pay attention to
- We have installed the required environment and software above, there may be some problems, we need to search some materials for modification. Please bear with me that I have not listed them one by one because everyone may encounter different problems here.
- Let’s create a Django project that uses IP and port to access the server.
Creating a Django project
- Create a Django project in the root directory
cd /
mkdir projects
cd projects
django-admin startproject test
Copy the code
- Create the test database
mysql -u root -p
creat database test;
Copy the code
* Settings file for the test project
DEBUG = False
ALLOWED_HOSTS = ['Your server IP']
INSTALLED_APPS = [
'django.contrib.admin'.'django.contrib.auth'.'django.contrib.contenttypes'.'django.contrib.sessions'.'django.contrib.messages'.'django.contrib.staticfiles'.'test' # Your project name
]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql'.'NAME': 'test'.'USER': 'root'.'PASSWORD': Mysql > select * from 'mysql ';.'HOST': 'localhost'.'PORT': '3306',}}Copy the code
⚠️ preferably a local project that works just drag it into the projects directory and make the changes above
- Execute data migration instructions
python3 manage.py makemigrations
python3 manage.py migrate
Copy the code
- Complete the Django project
Configuration of the nginx.conf file
- File path: /etc/nginx/nginx.conf
- Modify the following
The IP (if it is the aliyun ESC server) should use the private IP of the server
- Nginx some operation instructions
Service Starts systemctl stop nginx.service Suspends systemctl reload nginx.service Restarts systemctl status Nginx. service Checks the statusCopy the code
- Note: When you start nginx repeatedly, you need to kill the nginx process before you can start nginx otherwise there will be errors.
- Error document view path: / var/log/nginx/error. The log and/var/log/nginx/access. Log
Use and configuration of UWSGi
- Create the uwsgi.ini file under /projects/test (in the same directory as manage.py)
- Here’s what’s in the USWGI
[uwsgi]
wsgi-file=/server/http_practice/http_practice/wsgi.py
# Project Catalog
chdir=/projes/test
Specify the application for the project
module=test.wsgi:application
Sock file path
#socket= your IP+port number (nginx.conf) #socket= your IP+port number (nginx.conf)
# number of processes
workers=5
pidfile=uwsgi.pid
# Specify an IP portHTTP = 172.18.81.20:80# specify static files
#static-map=/static=/opt/proj/teacher/static
User name and user group to start UWSGi
uid=root
gid=root
# Enable the main process
master=true
# Automatically remove Unix Socket and PID files when the service stops
vacuum=true
Serialize the accepted content, if possible
thunder-lock=true
# enable thread
enable-threads=true
# Set the self-interrupt time
harakiri=30
# set buffer
post-buffering=4096
Set the log directory
daemonize=uwsgi.log
Copy the code
Start the project
- Start nginx: systemctl start nginx.service
- Ini (if the port is occupied, enter: sudo fuser -k 8080 (your configured port)/TCP)
- Access your Django project
- Browser input: IP+port+ url set in Django
Search for the browser access failure
Uwsgi error document query: / projects/test/uwsgi log (the file to start the uwsgi) will automatically generate nginx error document query: / var/log/nginx/error. The log and/var/log/nginx/access. LogCopy the code
conclusion
There will always be a lot of problems in development, and it is important to find out where the root cause of the problem is, where you can find a detailed description of the problem, and then follow the detailed description. Don’t blindly look up the question, let alone guess. Facing the browser, the key you type is closely related to the question so that you can accurately find the answer.
One article cannot solve all problems, much less everyone’s problems. Still the same words, step on the pit to have a deeper understanding of knowledge.