Nginx + UWSGI + Django under CentOS deployment Web services (Xia Baiyi)

Connect to the server

1) Account
>: ssh [email protected]
2) Password
>: ** ******

Server Command

Administrator Privilege
1) All of the following Server commands can be executed under administrator authority
>: sudo command
Configuration Terminal

Change the name to the prompt path:

1565349991138

1) Edit the configuration file
>: vim ~/.bash_profile

2) Delete all the original content
>: ggdG

3) Enter the editing state: fill in the two lines below
>: i

export PATH=$PATH:$HOME/bin
PS1='Path:\w\n>:'

4) Exit the editing state
>: esc

5) Save changes and exit
>: :wq

6) Effective configuration
>: source ~/ .bash_profile
Update system software package

The blogger here uses centos, and yum package manager can only be used in centos. If it is ubuntu, the default package manager is not yum, but dpkg. When installing the software, use apt-get to solve the common method on the Internet. The command is changed to the code: sudo apt-get install net-tools, and the installation is complete .

>: yum update -y
Installing the software management pack and possible dependencies
> : yum -y groupinstall "Development tools"
>: yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel

Install git

>: yum install git

Install Python3.6

1) Go to the user root directory
>: cd ~

2) Download or upload Python 3.6.7
>: wget https://www.python.org/ftp/python/3.6.7/Python-3.6 .7.tar.xz #wget download function
>: scp -r local Python-3.6.7.tar.xz ssh [email protected]: server path
>: scp -r C:\source \Python-3.6.7.tar.xz ssh [email protected]:~ # -r Upload both files and folders

3) Unzip the installation package
>: tar -xf Python-3.6.7.tar.xz

4) Enter the target file
>: cd Python-3.6.7

5) Configure the installation path: /usr /local/python3
>: ./configure --prefix=/usr/local/python3

6) Compile and install
>: make && sudo make install

7) Establish soft connection: terminal command python3, pip3
>: ln -s /usr/local/python3/bin/python3 /usr/bin/python3
>: ln -s /u sr/local/python3/bin/pip3.6 /usr/bin/pip3

8) Delete the installation package and files:
>: rm -rf Python-3.6.7
>: rm -rf Python-3.6.7.tar.xz

Configure pip source:

1) Create pip configuration path
>: mkdir ~/.pip

2) Enter the directory to edit the configuration file: fill in the following content
cd ~/.pip && vim pip.conf

[ global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban .com/simple/
trusted-host =pypi.douban.com

Installing virtual environment: default working path~/.virtualenvs< /h3>

workeron enter the virtual environment deactivate and exit

1) Installation dependencies
>: pip3 install virtualenv
>: pip3 install virtualenvwrapper

2 ) Establish virtual environment soft connection
>: ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv

3) Configure virtual environment: fill in the following content< br />>: vim ~/.bash_profile

VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/python3/bin/virtualenvwrapper.sh

4) Exit the editing state
>: esc

5) Save the modification and exit
>: :wq

6) Update the content of the configuration file< br />>: source ~ /.bash_profile

Install uwsgi

1) Install in real environment
pip3 install uwsgi

2) Create Soft connection
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi

Install a copy of uwsgi in the virtual environment and the real environment

Create a new virtual environment to run a Django project

Create a new virtual environment to run a Django project

1) Create Virtual environment
>: mkvirtualenv test_venv

2) Installation dependencies
>: pip install django

3) Go to the target directory and create the project working directory, Then enter
>: cd /home
>: mkdir project
>: cd project

4) Create a Django project and enter
>: django -admin startproject test_site
>: cd test_site

5) Complete the project configuration: modify the following lines
>: vim /home/project/test_site/test_site/settings.py

ALLOWED_HOSTS = ['*']
#DATABASES = {
#'default': {
#'ENGINE':'django.db.backends.sqlite3 ',
#'NAME': os.path.join(BASE_DIR,'db.sqlite3'),
# }
#}

6) Run native Service
>: python3 manage.py runserver 0.0.0.0:80

Install Nginx

1) Go to the user root directory
> : cd ~
2) Download nginx1.13.7
>: wget http://nginx.org/download/nginx-1.13.7.tar.gz

3) Unzip the installation package
>: tar -xf nginx-1.13.7.tar.gz

4) Enter the target file
>: cd nginx-1.13.7

5 ) Configure the installation path: /usr/local/nginx
>: ./configure --prefix=/usr/local/nginx

6) Compile and install
>: make && sudo make install

7) Establish soft connection: terminal command nginx
>: ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

8) Delete the installation package and files:
>: rm -rf nginx-1.13.7
>: rm -rf nginx-1.13.7.tar.xz

9) Test the Nginx environment, the server runs nginx, and the local access server ip
>: nginx
>: the domain name or ip:80 bound to the server

Nginx command

1) Start
>: nginx

2) Shut down nginx
>: nginx -s stop

3) Restart nginx
>: nginx -s reload

4) Check the port and close it forcibly
>: ps ​​-aux|grep nginx
>: kill
netstat -tunlp|grep 8000

Nginx & uwsgi run Django: enter the one with Django Virtual environment

1) Install uwsgi in the virtual environment of the project
>: workon test_venv
>: pip install uwsgi

2) Project root directory configuration uwsgi: fill in the following content
# Add uwsgi configuration
>: vim /home/project/test_site/test_site.xml

< uwsgi>
127.0.0.1:8808
/home/project/test_site/
test_site.wsgi
4
uwsgi.log


3) Complete the project Configuration: modify the following lines
# When we use uwsgi to start the project, it is not debug mode
>: vim /home/project/test_site/test_site/settings.py

DEBUG = False
# can be configured as * but it is strongly recommended to use specific ip
ALLOWED_HOSTS = ['47.103.31.166']

4) Go to the Nginx configuration directory, back up the configuration, Completely update the configuration: fill in the following content
>: cd /usr/local/nginx/conf
>: cp nginx.conf nginx.conf.bak # backup
>: vim nginx.conf
>: ggdG
>: i

events {
worker_connections 1024;
}
http {
include mime.types ;
default_type application/octet-stream;
sendfile on;
server {
listen 8000;
server_name 127.0.0.1; # Change to your own domain name, without domain name change to 127.0.0.1
charset utf-8;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8808; # The port should be the same as configured in uwsgi
uwsgi_param UWSGI_SCRIPT test_site.wsgi; #The directory name where wsgi.py is located+ .wsgi
uwsgi_param UWSGI_CHDIR /home/project/test_site/; # Project path
}
}
}

5) Start uwsgi
>: uwsgi -x /home/project/test_site/test_site.xml

6) Start nginx
>: nginx

7) Browser test: http: //39.100.155.49/admin

8) Close all uwsgi processes
>: pkill -f uwsgi -9

Configure foreground items

1) The project is locally packaged in the project root directory
npm run build # for streamlined packaging

2) Upload
scp -r dist ssh [email protected]:~

3)
mv -r dist /home/html

events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octe t-stream;
sendfile on;
server {
listen 8000;
server_name 127.0.0.1; # Change to your own domain name, and change the domain name to 127.0.0.1:80< br /> charset utf-8;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8808; # The port should be the same as that configured in uwsgi
uwsgi_param UWSGI_SCRIPT test_site. wsgi; #The directory name where wsgi.py is located+.wsgi
uwsgi_param UWSGI_CHDIR /home/project/test_site/; # Project path
}
}
server {
listen 80;
server_name 127.0.0.1; # Change to your own domain name, without domain name change to 127.0.0.1:80
charset utf-8;
location / {
root / home/html; #htmlAccess path
index index.html; #html file name
}
}
}

install Mysql

1) Go to the user root directory
>: cd ~

2) Download mysql57
>: wget http://dev.mysql.com /get/mysql57-community-release-el7-10.noarch.rpm

3) Install mysql57
>: yum -y install mysql57-community-re lease-el7-10.noarch.rpm
>: yum -y install mysql-community-server

4) Start mysql57 and check the startup status
>: systemctl start mysqld. service
>: systemctl status mysqld.service

5) Check the default password and log in
>: grep "password" /var/log/mysqld.log
> : mysql -uroot -p

6) Modify password
>: ALTER USER'root'@'localhost' IDENTIFIED BY'new password';

Install Redis

1) Go to the user root directory
>: cd ~

2) Download redis-5.0.5
>: wget http ://download.redis.io/releases/redis-5.0.5.tar.gz

3) Unzip the installation package
>: tar -xf redis-5.0.5.tar. gz

4) Enter the target file
>: cd redis-5.0.5

5) Compile environment
>: make
< br />6) Copy the environment to the specified path to complete the installation
>: cp -r ~/redis-5.0.5 /usr/local/redis

7) Configure redis to start in the background: Modify the following content
>: vim /usr/local/redis/redis.conf

daemonize yes

8) Complete configuration modification
>: esc
>: :wq

9) Establish a soft connection
>: ln -s /usr/local/redis/src/redis-server /usr/bin/redis-server
>: ln -s /usr/local/redis/src/redis-cli /usr/bin/r edis-cli

10) Run redis in the background
>: redis-server &
ctrl + c

11) Test the redis environment
>: redis-cli
ctrl + c

12) Turn off the redis service
>: pkill -f redis -9

Back-end project

Export dependent package:

pip freeze> Imported file name

Import dependent package:

Note that Xadmin needs to be downloaded separately

pip install -r file name

database configuration

"""Set authority account password# Authorized account command: grant authority (create, update) on library.table to'account'@'host' identified by'password'>: grant all privileges on luffy.* to 'luffy'@'%' identified by'luffy';# If the machine is not connected to mysql, add localhost access permission, the machine can log in>: grant all privileges on luffy.* to'luffy'@' localhost' identified by'luffy';# After setting up an account with restricted permissions, you must refresh the permissions. If there is no refresh permission, the terminal cannot be notified>: flush privileges; 7."""

< strong>There will be compatibility issues between Django and pymysql versions when running: see the two illustrations

Make the corresponding changes

share picture

share picture

Front-end separation project

When the front-end separation project is launched, it’s good to deal with cross-domain issues.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4878 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.