• luffy-项目上线


    1 上线前准备

    1.1 前端

    上线前配置

    settings.js
    # base_url: 'http://39.99.192.127:8000',  // 真实环境:django项目就是跑在8000端口上的

    之后编译

    # 前端执行 npm run build   把你写的vue代码编译成html,css,js

    项目架构:

    1.2 后端

    修改setting中的pro.py

    # 上线的配置文件
    from .const import *
    
    import os
    
    # 现在的BASE_DIR就是小luffyapi
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    
    import sys
    
    sys.path.insert(0, BASE_DIR)
    APPS_DIR = os.path.join(BASE_DIR, 'apps')
    sys.path.insert(1, APPS_DIR)
    
    # Quick-start development settings - unsuitable for production
    # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
    
    # SECURITY WARNING: keep the secret key used in production secret!
    SECRET_KEY = 'n(i@y4t6!n@)7l1ps$3ipz=9&3jutrpmuvu@uw*uyjo(r7&$+d'
    
    # SECURITY WARNING: don't run with debug turned on in production!
    DEBUG = False
    
    # 允许的host,正常情况填服务端地址(买的服务器的公网ip),
    ALLOWED_HOSTS = ['*']
    
    # Application definition
    
    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'rest_framework',
        'rest_framework_jwt',
        'corsheaders',
        # xadmin主体模块
        'xadmin',
        # 渲染表格模块
        'crispy_forms',
        # 为模型通过版本控制,可以回滚数据
        'reversion',
        'django_filters',
        'user',
        'home',
        'course',
        'order',
    ]
    MIDDLEWARE = [
        'django.middleware.security.SecurityMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        # 'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
        # 'luffyapi.utils.middles.CorsMiddleWare'
        'corsheaders.middleware.CorsMiddleware',
    ]
    
    ROOT_URLCONF = 'luffyapi.urls'
    
    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [os.path.join(BASE_DIR, 'templates')]
            ,
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                ],
            },
        },
    ]
    
    WSGI_APPLICATION = 'luffyapi.wsgi.application'
    
    # Database
    # https://docs.djangoproject.com/en/2.0/ref/settings/#databases
    
    # DATABASES = {
    #     'default': {
    #         'ENGINE': 'django.db.backends.sqlite3',
    #         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    #     }
    # }
    
    # 数据库配置
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'luffyapi',
            'USER': 'luffy',
            'PASSWORD': 'Luffy123?',
            'HOST': '127.0.0.1',
            'PORT': 3306
        }
    }
    
    import pymysql
    
    pymysql.install_as_MySQLdb()
    
    # Password validation
    # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
    
    AUTH_PASSWORD_VALIDATORS = [
        {
            'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
        },
    ]
    
    # Internationalization
    # https://docs.djangoproject.com/en/2.0/topics/i18n/
    
    LANGUAGE_CODE = 'zh-hans'
    
    TIME_ZONE = 'Asia/Shanghai'
    
    USE_I18N = True
    
    USE_L10N = True
    
    USE_TZ = False
    
    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/2.0/howto/static-files/
    
    STATIC_URL = '/static/'
    
    MEDIA_URL = '/media/'
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')  # 现在的BASEDIR是luffyapi下的luffyapi
    
    AUTH_USER_MODEL = 'user.User'
    
    REST_FRAMEWORK = {
        'EXCEPTION_HANDLER': 'luffyapi.utils.exceptions.common_exception_handler',  # 异常处理
    }
    
    # 配置日志字典
    standard_format = '%(levelname)s [%(asctime)s][%(threadName)s:%(thread)d][日志名:%(name)s][%(filename)s:%(lineno)d]' 
                      '[%(message)s]'
    
    simple_format = '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'
    
    # 日志配置字典
    LOGGING_DIC = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'standard': {
                'format': standard_format
            },
            'simple': {
                'format': simple_format
            }
        },
        'filters': {},
        'handlers': {
            # 打印到终端的日志
            'console': {
                'level': 'ERROR',
                'class': 'logging.StreamHandler',  # 打印到屏幕
                'formatter': 'simple'
            },
            # 打印到文件的日志,收集info及以上的日志
            'default': {
                'level': 'INFO',
                'class': 'logging.handlers.RotatingFileHandler',  # 保存到文件,日志轮转
                'formatter': 'standard',
                # 可以定制日志文件路径
                # BASE_DIR = os.path.dirname(os.path.abspath(__file__))  # log文件的目录
                # LOG_PATH = os.path.join(BASE_DIR,'a1.log')
                'filename': os.path.join(os.path.dirname(BASE_DIR), 'logs', 'luffy.log'),  # 日志文件
                'maxBytes': 300 * 1024 * 1024,  # 日志大小 5M,默认单位字节,日志大小达到5M就将其内容剪切到其他文件备份
                'backupCount': 10,  # 最大备份5份,备份文件名access.log.1,在filename名后.1或.2、.3。。。。
                'encoding': 'utf-8',  # 日志文件的编码,再也不用担心中文log乱码了
            }
        },
        'loggers': {
            'django': {
                'handlers': ['default', 'console'],  # 如果k为空,代表找不到k的时候用空k,并将日志名用这个空k
                'level': 'DEBUG',
                'propagate': False
            },
        },
    }
    CORS_ALLOW_CREDENTIALS = True
    CORS_ORIGIN_ALLOW_ALL = True
    # CORS_ORIGIN_WHITELIST = (
    #     '*'
    # )
    CORS_ALLOW_METHODS = (
        'DELETE',
        'GET',
        'OPTIONS',
        'PATCH',
        'POST',
        'PUT',
        'VIEW',
    )
    CORS_ALLOW_HEADERS = (
        'XMLHttpRequest',
        'X_FILENAME',
        'accept-encoding',
        'authorization',
        'content-type',
        'dnt',
        'origin',
        'user-agent',
        'x-csrftoken',
        'x-requested-with',
    )
    
    import datetime
    
    JWT_AUTH = {
        'JWT_EXPIRATION_DELTA': datetime.timedelta(days=7),  # 过期时间,手动配置
    }
    
    REST_FRAMEWORK = {
        'DEFAULT_THROTTLE_RATES': {
            'sms': '1/m'  # key要跟类中的scop对应
        },
    }
    
    # redis配置
    CACHES = {
        "default": {
            "BACKEND": "django_redis.cache.RedisCache",
            "LOCATION": "redis://127.0.0.1:6379",
            "OPTIONS": {
                "CLIENT_CLASS": "django_redis.client.DefaultClient",
                "CONNECTION_POOL_KWARGS": {"max_connections": 100}
                # "PASSWORD": "123",
            }
        }
    }
    # 后台基URL
    BASE_URL = 'http://47.114.55.57:8000'
    # 前台基URL
    LUFFY_URL = 'http://47.114.55.57'
    # 支付宝同步异步回调接口配置
    # 后台异步回调接口
    NOTIFY_URL = BASE_URL + "/order/success/"  # post回调,后台地址
    # 前台同步回调接口,没有 / 结尾
    RETURN_URL = LUFFY_URL + "/pay/success"   # get回调,前台地址
    pro.py

    项目根路径新建一个manage_pro.py(把原来的manage.py复制改动为上线的配置文件)

    #!/usr/bin/env python
    import os
    import sys
    
    if __name__ == "__main__":
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "luffyapi.settings.pro")
        try:
            from django.core.management import execute_from_command_line
        except ImportError as exc:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            ) from exc
        execute_from_command_line(sys.argv)
    manage_pro.py

    wsgi.py:改成线上的pro

    import os
    
    from django.core.wsgi import get_wsgi_application
    # wsgi用线上配置文件
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "luffyapi.settings.pro")
    
    application = get_wsgi_application()
    wsgi.py

    在项目目录生成依赖的关系文件requirement.txt

    # pip freeze >requirement.txt

    requirement.txt

    celery==4.4.6
    Django==2.0.7
    django-cors-headers==3.4.0
    django-filter
    django-redis
    qcloudsms_py
    djangorestframework==3.11.0
    djangorestframework-jwt==1.11.0
    Pillow==7.2.0
    PyMySQL==0.9.3
    python-alipay-sdk==2.0.1
    redis==3.5.3
    xadmin @ https://codeload.github.com/sshwsfc/xadmin/zip/django2

    2 上线

    2.1 重要

    更新系统软件包

    # yum update -y

    安装软件管理包和可能使用的依赖

    #  yum -y groupinstall "Development tools"   # 安装开发包
    #  yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel

    检测是否成功:会将git作为依赖安装号

    # git

     2.2 安装mysql

    1)前往用户根目录
    >: cd ~
    
    2)下载mysql57
    >: wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
    
    也可以本地上传,这条命令要在本地终端上执行
    >: scp -r C:UsersdellDesktoppkgmysql57-community-release-el7-10.noarch.rpm root@39.99.192.127:~
    
    3)安装mysql57
    >: yum -y install mysql57-community-release-el7-10.noarch.rpm
    >: yum -y install mysql-community-server
    
    4)启动mysql57并查看启动状态
    >: systemctl start mysqld.service
    >: systemctl status mysqld.service
    
    5)查看默认密码并登录
    >: grep "password" /var/log/mysqld.log
    >: mysql -uroot -p
    
    6)修改密码
    # ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
    >: ALTER USER 'root'@'localhost' IDENTIFIED BY '111111';

    创建数据库,配置用户

    1.管理员连接数据库
    >: mysql -uroot -p111111
    
    2.创建数据库
    >: create database luffyapi charset='utf8';
    
    3.查看用户
    >: select user,host,password from mysql.user;
    
        # 5.7往后的版本
        >: select user,host,authentication_string from mysql.user;
    
    4.为指定数据库配置指定账户
    """
    设置权限账号密码
    # 授权账号命令:grant 权限(create, update) on 库.表 to '账号'@'host' identified by '密码'
    
    1.配置任意ip都可以连入数据库的账户,通过luffy用户和密码可以对luffyapi数据库进行所有操作
    >: grant all privileges on luffyapi.* to 'luffy'@'%' identified by 'Luffy123?';
    
    2.由于数据库版本的问题,可能本地还连接不上,就给本地用户单独配置
    >: grant all privileges on luffyapi.* to 'luffy'@'localhost' identified by 'Luffy123?';
    
    3.刷新一下权限
    >: flush privileges;
    
    只能操作luffy数据库的账户
    账号:luffy
    密码:Luffy123?
    """

    2.3 安装redis

    安装依赖:

    #yum install gcc gcc-c++ -y //安装依赖文件

    redis软件包下载放在了/usr/local/src/目录下

    # 解压安装
    # cd /usr/local/src
    # wget http://download.redis.io/releases/redis-5.0.5.tar.gz
    [root@localhost src]# tar zxvf redis-5.0.5.tar.gz  //解压软件包
    [root@localhost src]# cd redis-5.0.5   //进入
    [root@localhost redis-5.0.5]# make PREFIX=/usr/local/redis install  //编译安装到指定目录
    #cp redis.conf /usr/local/redis/            //拷贝配置文件到redis下
    
    
    # 将/usr/local/redis/bin/目录加入至环境变量配置文件/etc/profile末尾,然后Shell终端执行source /etc/profile让环境变量生效
    # vi /etc/profile
    export PATH=/usr/local/redis/bin:$PATH  //文件末尾添加
    # source /etc/profile

    Nohup后台启动及停止Redis服务命令

    # nohup /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf & //启动redis
    #/usr/local/redis/bin/redis-cli  -p  6379 shutdown  //关闭redis
    #redis-cli  //启动客户端
    >keys *  //查看已有键值
    >FLUSHALL  //清空缓存中的数据

    2.4 安装Python3.6

    https://www.cnblogs.com/baicai37/p/12327279.html

    2.5 配置pip源:阿里云不用配置,默认配置阿里源

    https://www.cnblogs.com/baicai37/p/13322153.html

    2.6 安装nginx

    #安装PCRE库支持
    yum install pcre-devel pcre openssl openssl-devel gcc gcc-c++ zlib zlib-devel -y
    #下载Nginx源码包
    cd /usr/local/src 
    wget -c http://nginx.org/download/nginx-1.12.0.tar.gz
    #解压Nginx源码包
    tar -xzf nginx-1.12.0.tar.gz
    #进入解压目录,然后sed修改Nginx版本信息为JWS
    #cd nginx-1.12.0 
    #sed -i -e 's/1.12.0//g' -e 's/nginx//JWS/g' -e 's/"NGINX"/"JWS"/g' src/core/nginx.h  //用于隐藏Nginx版本号
    
    #预编译Nginx
    useradd www;./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
    
    #.configure预编译成功后,执行make命令进行编译并执行make install 正式安装
    make&&make install
    #至此Nginx WEB服务器安装完毕。
    #优化启动路径
    # ln -s /usr/local/nginx/sbin/nginx /usr/bin/

    nginx添加进系统服务中

    # vim /etc/init.d/nginx
    #!/bin/bash
    # chkconfig: - 85 15
    PATH=/usr/local/nginx
    DESC="nginx daemon"
    NAME=nginx
    DAEMON=$PATH/sbin/$NAME
    CONFIGFILE=$PATH/conf/$NAME.conf
    PIDFILE=$PATH/logs/$NAME.pid
    SCRIPTNAME=/etc/init.d/$NAME
    set -e
    [ -x "$DAEMON" ] || exit 0
    do_start() {
    $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
    }
    do_stop() {
    $DAEMON -s stop || echo -n "nginx not running"
    }
    do_reload() {
    $DAEMON -s reload || echo -n "nginx can't reload"
    }
    case "$1" in
    start)
    echo -n "Starting $DESC: $NAME"
    do_start
    echo "."
    ;;
    stop)
    echo -n "Stopping $DESC: $NAME"
    do_stop
    echo "."
    ;;
    reload|graceful)
    echo -n "Reloading $DESC configuration..."
    do_reload
    echo "."
    ;;
    restart)
    echo -n "Restarting $DESC: $NAME"
    do_stop
    do_start
    echo "."
    ;;
    *)
    echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
    exit 3
    ;;
    esac
    exit 0
    #chmod a+x /etc/init.d/nginx 
    #chkconfig --add nginx
    #chkconfig nginx on
    #systemctl start nginx
    //服务
    #启动nginx服务
    systemctl start nginx.service
    #停止nginx服务
    systemctl stop nginx.service
    #重启nginx服务
    systemctl restart nginx.service
    #重新读取nginx配置(这个最常用, 不用停止nginx服务就能使修改的配置生效)
    systemctl reload nginx.service

    补充知识:

    # nginx ,apache,uwsgi,gunicorn,php,jboss,tomcat,weblogic关系
        -nginx ,apache,IIS:http的转发
    
        -uwsgi(c语言写的),gunicorn(python写的):符合WSGI协议的web服务器,把http请求,转成python语言能识别的字典。。
        -tomcat(免费),jboss(收费):等同于咱们的uwsgi,符合javaweb的协议
        -php(服务器):等同于咱们的uwsgi,符合php的协议

    2.7 前端项目部署

    将装备阶段前端通过npm run build生成的dist文件夹上传到服务器

     部署

    # 创建目录
    # mkdir -p /var/www/html
    # 将/root/dist文件夹内容拷贝到/var/www/html
    # cp -r /root/dist/* /var/www/html/
    # 配置nginx.conf配置文件 # cd /usr/local/nginx/conf # vim nginx.conf #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; root /var/www/html; location / { root /var/www/html/; index index.html index.htm; try_files $uri $uri/ /index.html; # 解决单页面应用刷新404问题 } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }

    2.8 后台布置

    下载luffyapi项目

    # mkdir /home/project
    # cd /home/project
    
    # git clone https://gitee.com/baicaijc/luffyapi.git

    删除不必要文件

    # cd luffyapi/
    # rm -rf celerybeat-s*
    # cd luffyapi/apps/
    # cd course/
    # cd migrations/
    # cd ..
    # cd ../home/
    # cd migrations/
    # rm -rf 00*
    # cd ../../order/migrations/
    # cd ../../user/migrations/
    # rm -rf 0001_initial.py

    配置虚拟环境

    https://www.cnblogs.com/baicai37/p/13207983.html

    # mkvirtualenv luffy -p python3

    配置好之后,进入项目目录

    # cd /home/project/luffyapi/
    # mkdir logs   # 因为git时候忽略了
    # 安装依赖模块
    # pip install -r requirement.txt
    # 数据库迁移
    # python manage_pro.py makemigrations
    # python manage_pro.py migrate
    # 创建超级用户(用户名alias,密码admin@123)
    # python manage_pro.py createsuperuser

    2.9 安装uwsgi,并配置(真实环境和虚拟环境都需要安装,运行是在虚拟环境下运行)

    # 在真实环境下安装
    pip3 install uwsgi
        # 建立软连接
        ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi
    
    # 虚拟环境下安装
    workon luffy
    pip install uwsgi
    
    # 进行uwsgi服务配置,内容如下
    # vim /home/project/luffyapi/luffyapi.xml
    
    <uwsgi>    
       <socket>127.0.0.1:8808</socket> <!-- 内部端口,自定义 --> 
       <chdir>/home/project/luffyapi/</chdir> <!-- 项目路径 -->            
       <module>luffyapi.wsgi</module>  <!-- luffyapi为wsgi.py所在目录名--> 
       <processes>4</processes> <!-- 进程数 -->     
       <daemonize>uwsgi.log</daemonize> <!-- 日志文件 -->
    </uwsgi>

    启动uwsgi

    1)启动uwsgi
    (luffy) [root@aliyun ~]# uwsgi -x /home/project/luffyapi/luffyapi.xml
    
    2)关闭 uwsgi,重新启动 uwsgi
    (luffy) [root@aliyun ~]# pkill -f uwsgi -9
    (luffy) [root@aliyun ~]# uwsgi -x /home/project/luffyapi/luffyapi.xml

    2.10 完成uwsgi与nginx后台项目配置

    # vim /usr/local/nginx/conf/nginx.conf
    
    #user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
        server {
            listen       80;
            server_name  localhost;
            root /var/www/html;
            location / {
                root /var/www/html/;
                index  index.html index.htm;
                try_files $uri $uri/ /index.html; # 解决单页面应用刷新404问题
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
        server {
            listen       8000;
            server_name  localhost;
            root /var/www/html;
            location / {
               include uwsgi_params;
               uwsgi_pass 127.0.0.1:8808;  # 端口要和uwsgi里配置的一样
               uwsgi_param UWSGI_SCRIPT luffyapi.wsgi;  #wsgi.py所在的目录名+.wsgi
               uwsgi_param UWSGI_CHDIR /home/project/luffyapi/; # 项目路径
            }
        }
    
    }

    2.11 收集后端静态文件

    需要配置配置文件pro.py,在STATIC_URL下面添加两行

    STATIC_URL = '/static/'
    STATIC_ROOT = '/home/project/luffyapi/luffyapi/static'
    STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)

    开始收集

    # 项目目录下没有 static 文件夹需要新建
    >: mkdir /home/project/luffyapi/luffyapi/static
    
    # 完成静态文件迁移
    >: python /home/project/luffyapi/manage_pro.py collectstatic

    2.12 Nginx配置静态路径

    # vim /usr/local/nginx/conf/nginx.conf
    
    #user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
        server {
            listen       80;
            server_name  localhost;
            root /var/www/html;
            location / {
                root /var/www/html/;
                index  index.html index.htm;
                try_files $uri $uri/ /index.html; # 解决单页面应用刷新404问题
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
        server {
            listen       8000;
            server_name  localhost;
            root /var/www/html;
            location / {
               include uwsgi_params;
               uwsgi_pass 127.0.0.1:8808;  # 端口要和uwsgi里配置的一样
               uwsgi_param UWSGI_SCRIPT luffyapi.wsgi;  #wsgi.py所在的目录名+.wsgi
               uwsgi_param UWSGI_CHDIR /home/project/luffyapi/; # 项目路径
            }
            # 新增的配置静态文件
            location /static {
                alias /home/project/luffyapi/luffyapi/static;
            }
        }
    
    }

    2.13 重启nginx和uwsgi

    # 关闭 uwsgi,重新启动 uwsgi
    (luffy) [root@aliyun ~]# pkill -f uwsgi -9
    (luffy) [root@aliyun ~]# uwsgi -x /home/project/luffyapi/luffyapi.xml
    
    # 重新启动 nginx
    # systemctl restart nginx

    2.14 插入数据

    1)插入banner数据

    准备banner图片通过xadmin后台手动录入

    2)插入其他表数据

    -- 老师表
    INSERT INTO luffy_teacher(id, orders, is_show, is_delete, created_time, updated_time, name, role, title, signature, image, brief) VALUES (1, 1, 1, 0, '2019-07-14 13:44:19.661327', '2019-07-14 13:46:54.246271', 'Alex', 1, '老男孩Python教学总监', '金角大王', 'teacher/alex_icon.png', '老男孩教育CTO & CO-FOUNDER 国内知名PYTHON语言推广者 51CTO学院20162017年度最受学员喜爱10大讲师之一 多款开源软件作者 曾任职公安部、飞信、中金公司、NOKIA中国研究院、华尔街英语、ADVENT、汽车之家等公司');
    
    INSERT INTO luffy_teacher(id, orders, is_show, is_delete, created_time, updated_time, name, role, title, signature, image, brief) VALUES (2, 2, 1, 0, '2019-07-14 13:45:25.092902', '2019-07-14 13:45:25.092936', 'Mjj', 0, '前美团前端项目组架构师', NULL, 'teacher/mjj_icon.png', '是马JJ老师, 一个集美貌与才华于一身的男人,搞过几年IOS,又转了前端开发几年,曾就职于美团网任高级前端开发,后来因为不同意王兴(美团老板)的战略布局而出家做老师去了,有丰富的教学经验,开起车来也毫不含糊。一直专注在前端的前沿技术领域。同时,爱好抽烟、喝酒、烫头(锡纸烫)。 我的最爱是前端,因为前端妹子多。');
    
    INSERT INTO luffy_teacher(id, orders, is_show, is_delete, created_time, updated_time, name, role, title, signature, image, brief) VALUES (3, 3, 1, 0, '2019-07-14 13:46:21.997846', '2019-07-14 13:46:21.997880', 'Lyy', 0, '老男孩Linux学科带头人', NULL, 'teacher/lyy_icon.png', 'Linux运维技术专家,老男孩Linux金牌讲师,讲课风趣幽默、深入浅出、声音洪亮到爆炸');
    
    -- 分类表
    INSERT INTO luffy_course_category(id, orders, is_show, is_delete, created_time, updated_time, name) VALUES (1, 1, 1, 0, '2019-07-14 13:40:58.690413', '2019-07-14 13:40:58.690477', 'Python');
    
    INSERT INTO luffy_course_category(id, orders, is_show, is_delete, created_time, updated_time, name) VALUES (2, 2, 1, 0, '2019-07-14 13:41:08.249735', '2019-07-14 13:41:08.249817', 'Linux');
    
    -- 课程表
    INSERT INTO luffy_course(id, orders, is_show, is_delete, created_time, updated_time, name, course_img, course_type, brief, level, pub_date, period, attachment_path, status, students, sections, pub_sections, price, course_category_id, teacher_id) VALUES (1, 1, 1, 0, '2019-07-14 13:54:33.095201', '2019-07-14 13:54:33.095238', 'Python开发21天入门', 'courses/alex_python.png', 0, 'Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土', 0, '2019-07-14', 21, '', 0, 231, 120, 120, 0.00, 1, 1);
    
    INSERT INTO luffy_course(id, orders, is_show, is_delete, created_time, updated_time, name, course_img, course_type, brief, level, pub_date, period, attachment_path, status, students, sections, pub_sections, price, course_category_id, teacher_id) VALUES (2, 2, 1, 0, '2019-07-14 13:56:05.051103', '2019-07-14 13:56:05.051142', 'Python项目实战', 'courses/mjj_python.png', 0, '', 1, '2019-07-14', 30, '', 0, 340, 120, 120, 99.00, 1, 2);
    
    INSERT INTO luffy_course(id, orders, is_show, is_delete, created_time, updated_time, name, course_img, course_type, brief, level, pub_date, period, attachment_path, status, students, sections, pub_sections, price, course_category_id, teacher_id) VALUES (3, 3, 1, 0, '2019-07-14 13:57:21.190053', '2019-07-14 13:57:21.190095', 'Linux系统基础5周入门精讲', 'courses/lyy_linux.png', 0, '', 0, '2019-07-14', 25, '', 0, 219, 100, 100, 39.00, 2, 3);
    
    -- 章节表
    INSERT INTO luffy_course_chapter(id, orders, is_show, is_delete, created_time, updated_time, chapter, name, summary, pub_date, course_id) VALUES (1, 1, 1, 0, '2019-07-14 13:58:34.867005', '2019-07-14 14:00:58.276541', 1, '计算机原理', '', '2019-07-14', 1);
    
    INSERT INTO luffy_course_chapter(id, orders, is_show, is_delete, created_time, updated_time, chapter, name, summary, pub_date, course_id) VALUES (2, 2, 1, 0, '2019-07-14 13:58:48.051543', '2019-07-14 14:01:22.024206', 2, '环境搭建', '', '2019-07-14', 1);
    
    INSERT INTO luffy_course_chapter(id, orders, is_show, is_delete, created_time, updated_time, chapter, name, summary, pub_date, course_id) VALUES (3, 3, 1, 0, '2019-07-14 13:59:09.878183', '2019-07-14 14:01:40.048608', 1, '项目创建', '', '2019-07-14', 2);
    
    INSERT INTO luffy_course_chapter(id, orders, is_show, is_delete, created_time, updated_time, chapter, name, summary, pub_date, course_id) VALUES (4, 4, 1, 0, '2019-07-14 13:59:37.448626', '2019-07-14 14:01:58.709652', 1, 'Linux环境创建', '', '2019-07-14', 3);
    
    -- 课时表
    INSERT INTO luffy_course_Section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (1, 1, 0, '2019-07-14 14:02:33.779098', '2019-07-14 14:02:33.779135', '计算机原理上', 1, 2, NULL, NULL, '2019-07-14 14:02:33.779193', 1, 1);
    
    INSERT INTO luffy_course_Section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (2, 1, 0, '2019-07-14 14:02:56.657134', '2019-07-14 14:02:56.657173', '计算机原理下', 2, 2, NULL, NULL, '2019-07-14 14:02:56.657227', 1, 1);
    
    INSERT INTO luffy_course_Section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (3, 1, 0, '2019-07-14 14:03:20.493324', '2019-07-14 14:03:52.329394', '环境搭建上', 1, 2, NULL, NULL, '2019-07-14 14:03:20.493420', 0, 2);
    
    INSERT INTO luffy_course_Section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (4, 1, 0, '2019-07-14 14:03:36.472742', '2019-07-14 14:03:36.472779', '环境搭建下', 2, 2, NULL, NULL, '2019-07-14 14:03:36.472831', 0, 2);
    
    INSERT INTO luffy_course_Section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (5, 1, 0, '2019-07-14 14:04:19.338153', '2019-07-14 14:04:19.338192', 'web项目的创建', 1, 2, NULL, NULL, '2019-07-14 14:04:19.338252', 1, 3);
    
    INSERT INTO luffy_course_Section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (6, 1, 0, '2019-07-14 14:04:52.895855', '2019-07-14 14:04:52.895890', 'Linux的环境搭建', 1, 2, NULL, NULL, '2019-07-14 14:04:52.895942', 1, 4);

    2.15 线上测试

  • 相关阅读:
    C#下编程完成IIS网络App的权限设置
    IIS6与IIS7在编程实现HTTPS绑定时的细微差别
    Android 对话框(Dialog)大全
    Android 开发中使用Intent传递数据的方法
    设计模式--模版设计模式
    android 布局页面文件出错故障排除Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V
    viewPager的切换动画
    设计模式--状态模式
    git学习
    二〇一五年五月二十二日--bug--启动页面出现模糊的问题
  • 原文地址:https://www.cnblogs.com/baicai37/p/13407477.html
Copyright © 2020-2023  润新知