部署-打包并提交代码到Git服务器

前期准备工作
vue.config.js

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  // 项目出Bug,点击错误可以跳到对应的位置,实际生成环境是不需要的 默认为true
  productionSourceMap: false,
  lintOnSave: false,
  publicPath: process.env.NODE_ENV === "production" ? "/static/" : "/",
})

socket.js

  constructor() {
    if(process.env.NODE_ENV == "production"){
      this.server_host = window.location.origin
    }else{
      this.server_host = "http://127.0.0.1:5000";
    }
    this.socket = io(this.server_host);
  }

在终端输入下面命令进行打包

npm run build

将生成的这四个部分放置到服务端static中
在这里插入图片描述
在这里插入图片描述

生成的index.html放到templates中

app.py中渲染模板

@app.route("/")
def index():
    return render_template("index.html")

连接服务器
tabby

添加一个用户
在这里插入图片描述

cd lixuan/
mkdir chat
cd chat
apt update

   error:lixuan is not in the sudoers file.  This incident will be reported.

	解决办法: 执行su -  切换到root  将指定用户添加到root  执行adduser lixuan sudo

apt install git -y

代码拉下来之后直接执行

pip install -r requirements.txt

需要添加环境变量

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

source .bashrc

这时就可以使用flask进行启动了
安装

pip install gunicorn

执行下面命令

gunicorn --worker-class=eventlet --workers=1 --bind=0.0.0.0:5000 app:app

可以把对应的文件夹创建下
在这里插入图片描述

部署-使用Nginx和Gunicorn部署项目

sudo apt install nginx
cd /etc/nginx/conf.d/
touch chat.conf
vi chat.conf
server {
    listen 80;
                如果映射了域名可替换此ip
    server_name 47.116.114.26;

    location / {
        include proxy_params;
        proxy_pass http://127.0.0.1:5000;
    }

    location /static {
        alias /home/lixuan/chat/chat/static;
        expires 30d;
    }

    location /socket.io {
        include proxy_params;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        # 如果使用socket.io这个框架  后缀会自动加上
        proxy_pass http://127.0.0.1:5000/socket.io;
    }
}

测试nginx

service nginx configtest
结果:* Testing nginx configuration 

sudo service nginx restart

启动服务

gunicorn --worker-class=eventlet --workers=1 --bind=127.0.0.1:5000 app:app

在这里插入图片描述

上面的启动方式会卡终端
新建gunicorn.conf.py

worker_class = "eventlet"
workers=1
bind = "0.0.0.0:5000"
accesslog = "/home/lixuan/chat/chat/log/access.log"
errorlog = "/home/lixuan/chat/chat/log/error.log"
daemon=True

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

季布,

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值