在Linux上部署SpringBoot前后端分离的项目

1、把后端spring boot项目打成jar包,传到Linux上
2、在Linux上运行jar包
(1)、java -jar xxx.jar; 关闭服务器连接时会关闭此程序进程,(推荐测试可用)
(2)、将jar程序设置成后台运行,并且将标准输出的日志重定向至文件xxx.log
nohup java -jar xxx.jar >xxx.log 2>&1 &;
nohup命令的作用就是让程序在后台运行,不用担心关闭连接进程断掉的问题了(推荐使用)

详解:
nohup
nohup命令运行由Command参数和任何相关的Arg参数指定的命令,忽略所有挂断(SIGHUP)信号。
在注销后使用 nohup 命令运行后台中的程序。要运行后台中的 nohup命令,添加 &(表示“and”的符号)到命令的尾部。
nohup是no hang up的缩写,就是不挂断的意思。
nohup命令:如果你正在运行一个进程,而且你觉得在退出帐户时该进程还不会结束,那么可以使用nohup命令。
该命令可以在你退出帐户/关闭终端之后继续运行相应的进程。
在缺省情况下该作业的所有输出都被重定向到一个名为nohup.out的文件中。

nohup和&的区别
&:指在后台运行,但当用户推出(挂起)的时候,命令自动也跟着退出
nohup:不挂断的运行,注意并没有后台运行的功能,,就是指,用nohup运行命令可以使命令永久的执行下去,和用户终端没有关系,
例如我们断开SSH连接都不会影响他的运行,注意了nohup没有后台运行的意思;&才是后台运行。

nohup java -jar jarName-0.0.1-SNAPSHOT.jar >msg.log 2>&1 &;
在上面的例子中,0:stdin (standard input)1:stdout (standard output)2:stderr (standard error)2>&1是将标准错误(2)重定向到标准输出(&1),标准输出(&1)再被重定向输入到msg.log文件中。

(3)、重新部署时

ps -ef|grep java;
找到此进程: 
root  9836  0.1  4.6 10903144 1522292 ?  Sl   Nov08   1:31 java -jar xxx.jar
执行:  kill -9 9836 杀死进程;:  9836 为进程标识号
(Linux下还提供了一个killall命令,可以直接使用进程的名字而不是进程标识号,例如:#killall -9 name)
然后再重新执行一下nohup命令即可。

3、部署前端项目
(1)、在Linux上安装nginx,安装步骤请自行百度
(2)、修改vue项目的config文件夹下的index.js文件
在这里插入图片描述
修改内容

'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')

module.exports = {
  dev: {

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      '/api': {
        // target: 'http://localhost:8089',//本地地址
        target: 'http://xxx.xx.xx.xxx:8089',// 线上部署地址
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''//这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可
        }
      }
    },

    // Various Dev Server settings
    // host: 'localhost', // can be overwritten by process.env.HOST
    host: 'localhost',
    port: 8088, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-


    /**
     * Source Maps
     */

    // https://webpack.js.org/configuration/devtool/#development
    devtool: 'cheap-module-eval-source-map',

    // If you have problems debugging vue-files in devtools,
    // set this to false - it *may* help
    // https://vue-loader.vuejs.org/en/options.html#cachebusting
    cacheBusting: true,

    cssSourceMap: true
  },

  build: {
    // Template for index.html
    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',

    /**
     * Source Maps
     */

    productionSourceMap: true,
    // https://webpack.js.org/configuration/devtool/#production
    devtool: '#source-map',

    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],

    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  }
}

线上地址可以是域名或者是服务器的IP地址
(3)、在vue项目下执行npm run build,会在项目的目录下生成dist文件夹
(4)、把dist文件夹上传到Linux上(我是上传到/usr/local/nginx下的test文件夹下(test文件夹是我自己创建的))
(5)、修改nginx的conf/nginx.conf文件


    server {
        listen       80;
        server_name  xxx.xx.xx.xx;     
		#注意:server_name 要和vue项目中写的一样,可以是IP地址或者域名
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        #root   /usr/local/nginx/test/dist;

        location / {
            root   /usr/local/nginx/test/dist3;
            index  index.html index.htm;
        }

        location /api {
            proxy_pass http://xxx.xx.xx.xxx:8089/;
            #proxy_pass  是后端项目的部署地址,8089就是springboot的项目启动的端口号
        }

(6)、重启nginx
nginx安装路径下的/sbin/nginx -s reload

nginx的常用命令
启动 nginx安装路径下的/sbin/nginx
停止 nginx安装路径下的/sbin/nginx -s stop
重启 nginx安装路径下的/sbin/nginx -s reload
查看进程 ps -ef | grep nginx

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值