SoFunction
Updated on 2025-03-04

Detailed explanation of Vue+Django project deployment

Local project configuration

1 Copy luffy/settings/

Modify the following items in luffy/settings/

(1) allow_hosts

ALLOWED_HOSTS = [
'',
]

(2) Cross-domain whitelist

CORS_ORIGIN_WHITELIST = (
# Front-end domain name"", 
# Backend API interface domain name""
)

(3) Payment configuration information of Alipay computer website

ALIPAY_APPID = "xxxxxxx"
APP_NOTIFY_URL = None
ALIPAY_DEBUG = True
# APIPAY_GATEWAY="/"
APIPAY_GATEWAY = "/"
ALIPAY_RETURN_URL = "/success"
ALIPAY_NOTIFY_URL = ":8000/payments/success"

2 Modify luffy/file

Line 14

("DJANGO_SETTINGS_MODULE", "")

3 Modify the file

It's OK to not change, for easier testing on the server

Line 6

("DJANGO_SETTINGS_MODULE", "")

4 Export the package list installed by pip

freeze > docs/

5 Collect static files

python  collectstatic

6 Submit and push

git add .
git commit -m "Project Completed"
git push -u origin master

7 Front-end configuration modification src/

Set up the backend server domain name and port

Host::80,

8 Build

npm run build

9 Submit and push

git add .
git commit -m "Project Completed"
git push -u origin master

Configuration on the server

1 Install the required software

yum install  python36.x86_64 python36-devel.x86_64 nginx git gcc -y
pip3 install virtualenv -i /simple

Note: It is best to install uwsig using pip

pip3 install uwsgi -i /simple

2 mysql database related configuration

(1) Install mysql

yum install mysql-server -y

Or use containers

Please solve the problem by setting password and initializing configuration.

(2) Start the database

systemctl start mysqld

(3) Create a new database luffy

create database luffy;

(4) Import data

mysql -uroot -pmysql luffy < 

3 redis installation and configuration

You can use yum to install and start it, it is simple and crude!

To use the latest version, I use unzip installation

That way you like it!

(1) Download

cd /opt/
wget /releases/redis-5.0.

(2) Unzip and install

tar -xf redis-5.0.
cd /opt/redis-5.0.5
make && make install

(3) Modify the configuration file

vim
69 lines bind 127.0.0.1
Change to bind 0.0.0.0

(4) Start Redis and place it in the background

nohup redis-server  &

4 Pull the front-end project

cd /opt/
git clone /SunHarvey/

The front-end project path is /opt/luffyweb/

Only the /opt/luffyweb/dist/ file is useful,

dist is used as the front-end root directory, and other things are not allowed!

5 Create a virtual environment

(1) Create a virtual environment

cd /opt/
virtualenv luffy 

That is, the virtual environment path is /opt/luffy/

cd /opt/luffy/

(2) Activate the virtual environment

source /opt/luffy/bin/activate

(3) Pull backend project

git clone /SunHarvey/

Note: The root path of the project is /opt/luffy/luffy/

cd luffy

You can see the following file

docs luffy  scripts static

(4)Pip installation required package

My django is using version 2.0, and there is no need to report the source code because pymysql error

Delete the line in xadmin in luffy/docs/

pip3 install /sshwsfc/xadmin/zip/django2
pip3 instal -r /opt/luffy/luffy/docs/

(5) Use runserver to start the django project to see if it is normal

Remember to start MySQL database and redis

python  runserver

If there is no error, continue. If the error is reported, please exclude it according to the prompts.

6 uwsgi configuration

(1) The configuration content is as follows

vim /opt/luffy/luffy/
[uwsgi]
# Set uwsgi to start the user. If you don't set it, there will be a warning, and it can also be set as the currently logged in user.uid = nginx
gid = nginx
#Use when using nginx connection, the server address where the Django program is locatedsocket=127.0.0.1:8000
# Directly use the web server, the server address where the Django program is located#http=0.0.0.0:8080
#Project Directorychdir=/opt/luffy/luffy
#The directory of files in the project, relative to the directory of the projectwsgi-file=luffy/
# Number of processesprocesses=1
# Number of threadsthreads=2
# The role of uwsgi servermaster=True
# Files that store process numberpidfile=
# Log file, because uwsgi can run in the background from the terminal, the log cannot be seen.  Our previous runserver was dependent on the terminaldaemonize=
# Specify the dependent virtual environmentvirtualenv=/opt/luffy/
# clear environment on exit #Clear environment on exitvacuum = true

(2) Modify the file owner, if you start with root, you can ignore this step

chown -R  /opt/luffy/luffy/

You can also replace nginx with the user name of the currently logged in user, and other users can do it.

(3) Start uwsgi, remember to start MySQL database and redis

uwsgi --ini /opt/luffy/luffy/

7 nginx configuration

(1) Create a configuration file

vim /etc/nginx// 
# Set up the backend uwsgi server, and write multiple ones for load balancingupstream luffy {
server 127.0.0.1:8000;
}
# Backend API server configurationserver {
listen 80;
server_name ;
location / {
include uwsgi_params;
uwsgi_pass luffy;
}
# Load css and js fileslocation ~ .*\.(css|js)$ {
root /opt/luffy/luffy/;
}
}

# Front-end page server configurationserver {
listen 80;
# Don't doubt, you read it right!  nginx's 80 port can start n domain names!server_name  ;
location / {
# /opt/luffyweb/dist/ Folder generated for npm run buildroot /opt/luffyweb/dist/;
index ;
try_files $uri $uri /;
}
}

This is the most basic configuration, and I won’t repeat the other optimized configurations!

(2) Check nginx configuration file syntax

nginx -t

(3) Start nginx

systemctl start nginx

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.