美文网首页
手动发布一个golang+vue的web项目到服务器上的步骤

手动发布一个golang+vue的web项目到服务器上的步骤

作者: bug去无踪 | 来源:发表于2020-01-16 21:08 被阅读0次

    B/S架构的web项目打包发布流程:
    (事先安装好数据库、supervisord进程管理工具、nginx)

    手动打包程序:(先上在服务器建好相应的目录,日志:.log,部署:.ini文件,项目可执行文件目录)

    (1)打包为linux可执行的程序:GOOS=linux go build

    (2)上传到服务器:scp 打包好的本地可执行文件名称 服务器用户名@服务器地址:服务器存放程序打包后的可执行文件目录
    scp rentcarapisrv tonnn@服务器ip:/home/zhangsan/rentcarapisrv/

    (3)建好日志存放的目录
    第一次配置时加入在supervisordctl 配置文件 /etc/supervisord.conf 中加入
    [include]
    ;files = relative/directory/.ini(配置文件中本来就有)
    files = /etc/supervisord.d/
    .ini(新加入的配置) --各个程序进程配置文件存放的目录

    (4)配置程序进程管理文件.ini
    模版:
    [program:rentcarapisrv]
    directory=/home/zhangsan/rentcarapisrv/
    command=/home/zhangsan/rentcarapisrv/rentcarapisrv -config=/home/zhangsan/rentcarapisrv/qcloud.toml -mode=RELEASE
    stdout_logfile=/data/log/rentcarapisrv/rentcarapisrv.log
    stdout_logfile_backups=50
    redirect_stderr=true
    autostart=true
    autorestart=true

    (5)将新构建的进程加入进程管理任务列表中: sudo supervisorctl update(到此后台部署完毕)

    // 部署前端
    (6)前端拷贝打包代码方法和后台程序一致(例如vue项目打包:npm node build )将生成的dist可执行文件上传到服务器

    (7)增加nginx配置文件 zhangsan.conf
    文件内容:

    server {
    listen 9988(默认80端口);
    server_name api.rentcar.com;

    #charset koi8-r;
    access_log  /var/log/nginx/log/zhangsan.access.log  main;#nginx文件日志
    error_log   /var/log/nginx/log/zhangsan.error.log;
    
    location / {
        root   /home/zhangsan/rentcarapp/dist; #前端可执行文件在服务器上的目录
        index  index.html index.htm;
    }
    
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    
    location ~\.(jpg|jpeg|png|js|css) {
        root /home/zhangsan/rentcarapp/dist;#前端静态资源在服务器上的目录
        expires 30d;
    }
    

    (8)让nginx配置文件生效
    第一步:sudo nginx -t 检测配置是否生效

    第二步:sudo nginx -s reload(重新加载nginx)

    (9) 浏览器访问 http://api.rentcar.com/

    相关文章

      网友评论

          本文标题:手动发布一个golang+vue的web项目到服务器上的步骤

          本文链接:https://www.haomeiwen.com/subject/cxjqzctx.html