Deploy a back-end code
1 django package
1 setup.py file creation
Details are as follows
#!/usr/bin/poython3.6
#conding:utf-8
from distutils.core import setup
import glob
setup(name='blog',
version='1.0',
description='demo blog',
author='zhang',
author_email='[email protected]',
url='https://www.zhang.com',
packages=['blog','post','user'], # 打包py文件
py_modules=['manage'], #可以不打包manage.py文件
data_files=glob.glob('templates/*.html') + ['requirements','manage.py'], # 打包其他文件
)
2 under the root directory of the application package as
Related dependency derivation installation configuration
pip freeze > requirements # 此处的文件名需要和上面的需要打包中的其他文件的文件名相同
The following information
2 pack
python setup.py sdist --formats=gztar #此处表明打包文件为tar.gz
as follows
2 Deployment
1 Create a directory and associated virtual environments and processes
mkdir blog01
cd blog01/
pyenv virtualenv 3.5.3 blog01
pyenv local blog01
The results are as follows
Installation and deployment of dependencies 2
1 installation of dependencies
yum -y install mysql-devel python-devel
2 Deployment
Copy under the previous package to this directory and unpack rename
Installation-related project dependencies
cd blog/
pip install --upgrade pip # 升级安装包
pip install -r requirements
Check the installation results
Start Service
python manage.py runserver 0.0.0.0:80
The results are as follows
Tests are as follows
Two UWSGI
1 WSGI Overview
web server gateway interface, the interface is defined Web Server and applications as defined in python
There WSGI application of django responsible, and the WSGI server can be responsible by UWSGI
2 UWSGI
UWSGI is a C language program, provide a WEB server that supports WSGI protocol, and the python WSGI application communication.
Official Documents
https://uwsgi-docs.readthedocs.io/en/latest/
UWSGI HTTP service can be started directly accept HTTP requests. And calls django application
3 Installation and Configuration
1 Installation
pip install uwsgi
Check whether the installation is successful
2 uWSGI + Django project deployment
Root directory as follows
Run the following code in django project root directory
uwsgi --http :8000 --wsgi-file blog/wsgi.py --stats :8001
Tests are as follows
Above indicate normal operation
Three nginx configuration
1 HTTP nginx reverse proxy configuration
The basic environment is as follows
Configuration as follows
Modify the configuration file and add the following /etc/nginx/conf.d/default.conf
location ^~ /api/ {
rewrite ^/api(/.*) $1 break; #重写URL,去掉前面的api,$1表示去掉api后对应的url
proxy_pass http://192.168.1.200:8000;
}
The entry into force configuration is as follows
systemctl reload nginx
Tests are as follows
2 deployment UWSGI
Nginx UWSGI direct current and communication using HTTP, inefficiencies, the need to modify the communication uwsgi
1 Create a file blog.ini
The root of a sub-item is / root / blog01 / blog, so blog.ini placed in this directory, the content is as follows
[uwsgi]
socket=127.0.0.1:9000
chdir=/root/blog01/blog
wsgi-file=blog/wsgi.py
Start Service
uwsgi blog.ini
as follows
2 as modified reverse proxy nginx
location ^~ /api/ {
rewrite ^/api(/.*) $1 break;
#proxy_pass http://192.168.1.200:8000;
include uwsgi_params;
uwsgi_pass 127.0.0.1:9000;
}
Valid configuration and reload
systemctl reload nginx
Tests are as follows
Four front-end project package
1 react packaged items
1 rimraf installation
Its role is to recursively delete files, the equivalent of rm -rf
npm install rimraf --save-dev
2 package.json arrangement
Package.json replaced with the following results
The action of the build is performed when a call build build command corresponding
Modify the following webpack.config.prod.js
3 Build
npm run build
Package upload
Modify the configuration following nginx
Reload configuration is as follows
Visit the following
The basic blog platform deployed