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

歼灭bug · · 1742 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

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

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

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

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


有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:歼灭bug

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

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1742 次点击  ∙  1 赞  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传