linux服务器上前后端部署流程

linux服务器上前后端部署流程

本文介绍如何在Linux上部署前段和后端的流程,以及遇见的bug

Vue前端部署流程

  1. 首先,在服务器上(本文以华为云服务器为例)开启80端口;
  2. 在服务器上下载nginx;
// 更新apt源
 sudo apt update
// nginx下载
 sudo apt install nginx
  1. 将前端代码git到/var/www/html路径下面;
// git
 cd /var/www/html
 git clone xxxx
// 在前端中global_variable.js文件的本地测试端口需要全部修改
const baseURL = 'http://xxx.xx.xx.xx/db'
// const baseURL = 'http://127.0.0.1:5000/'
export default {
    baseURL,
}
// build前端生成dist静态文件
 cd smjk-portal-v
 npm install
 npm run build
  1. 进入到nginx中的目录中,进行修改;
// 默认在/etc/nginx中
 cd /etc/nginx/sites-available
 vim default
// 在default文件中的server添加新的信息
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html/smjk-portal-v/dist; **// 修改此路径**

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
        location /smjk {
                  alias /var/www/html/smjk-portal-v/dist; **// 修改此路径**
                  try_files $uri $uri/ $uri.html /index.html;
        }
        location /db {
                proxy_pass http://127.0.0.1:5000/;
        }
        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}
// 重启nginx服务
 sudo systemctl restart nginx
  1. 进入网站,现实页面即成功。
    在这里插入图片描述

  2. 若需要https证书,则需要去阿里云申请对应证书。

flask后端部署流程

  1. 首先,在相关目录下git后端项目;
 cd ~/demo
 git clone xxxxx
 cd smjk-flask
  1. 安装anaconda,用于配置项目环境(本文省略了安装流程);
// 创建新的环境
 conda create smjk
// 激活环境
 conda activate smjk
// 安装相关库
 pip install -r requirements.txt
  1. 数据库配置,本文所用MongoDB数据库
// 导入json数据
 mongoimport --db xxx --collection xxx --jsonArray ~/xxx.json
  1. 服务器持续运行文件
cd ~/demo/smjk-flask
 nohup python -u run.py > test.out 2>&1 &
 // 运行后会返回一个pid,可以随时kill该进程
 [1] 1601
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值