Lu Feixue city deploying vue+django

Posted by faizanno1 on Sun, 12 Apr 2020 14:51:09 +0200

Lu Feixue city deploying vue+django


Deployment of Luffy Learning City

One day, Ritian sent me two mysterious codes. It's said that they are the crystallization of mjj


I put these two codes on a website. You can download them by yourself

Lu Fei Xue Cheng django Code
vue Code

1, Get the code to the server

stay linux Download directly from
Download it on window s and transfer it to linux server through lrzsz or xftp

2, Start with the front end vue

To compile and package a vue project on the server, you must have a node environment

download node Binary package, which already contains node,No need to recompile
tar -zxvf node-v8.6.0-linux-x64.tar.gz
//Enter the node folder
[root@web02 opt]# cd node-v8.6.0-linux-x64/
[root@web02 node-v8.6.0-linux-x64]# ls
bin  etc  include  lib  LICENSE  share
[root@web02 node-v8.6.0-linux-x64]# ls bin
node  npm  npx
[root@web02 node-v8.6.0-linux-x64]# ./bin/node -v
[root@web02 node-v8.6.0-linux-x64]# ./bin/npm -v

Add node command to linux environment variable, modify / etc/profile, and write


Read file, effective PATH

source /etc/profile

Test path

[root@web02 node-v8.6.0-linux-x64]# node -v
[root@web02 node-v8.6.0-linux-x64]# npm -v

With node environment, install node module and package node project

Enter the vue source directory
cd 07-luffy_project_01/
Install the vue module. By default, install the module content of package.json. If the module installation fails, manually reinstall it
npm install 

At this time, note that the vue code you wrote locally and the server address that the interface is likely to connect to have problems. Note that the address submitted by Axios.POST must be sent to the django application (if nginx is used, it will be sent to the entry port of nginx)
In order to facilitate the experiment, we put the vue project and django project on a server, and forward the vue request to django(9000) through the nginx reverse proxy function (8000 port)

Prepare to compile and package vue project, replace all addresses of configuration file, and change to server address
sed -i 's/' /opt/07-luffy_project_01/src/restful/api.js
 At this time, package the vue project and generate a dist static folder
npm run build
Check the dist folder [root@web02 07-luffy_project_01]# ls dist/ index.html static

At this point, the vue code is over. Just configure nginx and find the index.html homepage file of vue

nginx will not be explained here, just compile and install it

server {
     #When users access domain name or ip, the default is port 80 of nginx
listen 80; server_name;
     #When the url match / request address is, enter this location and return to the homepage of index.html Luffy Learning City under the dist of vue location / { root /opt/07-luffy_project_01/dist; index index.html; } }

3, Configure the back-end code, solve the virtual environment, and ensure the clean isolation of the project

Activate the virtual environment venv1, and install the dependent modules required by Luffy project in the virtual environment

[root@web02 opt]# cat requirements.txt

This Luffy code database uses sqllite, so there is no need to configure the database

The shopping cart uses redis, so you need to start the redis server server of the server

redis-server /etc/redis.conf

ps -ef|grep redis
redis-server *:6379

Launch Luffy project through uwsgi

# Django-related settings
# the base directory (full path)
chdir           = /opt/luffy_boy
# Django's wsgi file
module          = luffy_boy.wsgi
# the virtualenv (full path)
home            = /opt/venv1
# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 1
# the socket (use the full path to be safe
socket          =
# clear environment on exit
vacuum          = true
#Running uwsgi in the background
(venv1) [root@web02 opt]# uwsgi --ini luffy_boy/uwsgi.ini

4, Configure nginx, this step is important

worker_processes  1;

events {
    worker_connections  1024;

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        location / {
            root /opt/07-luffy_project_01/dist;
            index index.html;
            try_files $uri $uri/ /index.html;  # In order to solve the problem of refreshing 404 errors, you need to use this line configuration
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
           root   html;

    server {
        listen 8000;
        location / {
            include /opt/nginx/conf/uwsgi_params;
        location /static {
            alias /opt/static;


Schematic diagram

Project access

Test account password


Current code function demonstration, demonstration process:

  1. Log in to alex account
  2. Choose a free course and learn from django framework
  3. Add courses to shopping cart, check the shopping cart record of alex account, and redis will have data after adding successfully


Topics: Linux Vue Django Nginx