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. 进入网站,现实页面即成功。
    linux服务器上前后端部署流程_第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

你可能感兴趣的:(服务器,linux,nginx)