在服务器上打包部署springboot+vue的项目(一)启动tomcat后打开浏览器点击登录无反应 页面空白问题

先记录查看与关闭端口的命令:

netstat -ano|findstr “8080”
taskkill /pid 5588 /f
打开某个端口:
netsh firewall add portopening protocol = TCP port = 8080 name = “Open8080” mode = Enable
查看进程: services.msc

配置

购买的腾讯轻量应用服务器,27R 3个月 内存2G 硬盘64G
ping 自己的ip地址:

在这里插入图片描述

什么是轻量应用服务器 Lighthouse? 轻量应用服务器
Lighthouse
是一种易于使用和管理、适合承载轻量级业务负载的云服务器,能帮助个人和企业在云端快速构建网站、博客、电商、论坛等各类应用以及开发测试环境,并提供应用部署、配置和管理的全流程一站式服务,极大提升构建应用的体验,是您使用腾讯云的最佳入门途径。

轻量应用服务器与云服务器 CVM 的区别是什么? 轻量应用服务器 Lighthouse 对比云服务器
CVM,轻量应用服务器更加简单易用,融合多款云产品和应用服务能力,简化了传统云服务器的高阶概念及功能,帮助开发者更加专注于业务逻辑与创新。详情请参见
产品对比。

首先买了以后可以设置Administrator的密码,然后可以从这里进入
在这里插入图片描述
进入服务器的图形界面,也可以从自己电脑远程进入(输入IP 用户名和密码)
在这里插入图片描述
自己的项目前端是vue3.0框架,后端有springboot和flask(后者用于深度学习),由于接触计网的知识不多,所以对于服务器、http、ftp等协议方面还只是粗略了解,望指正。

解决tomcat启动中文乱码:
修改logging.properties
在这里插入图片描述
改为GBK

打包前端:

前端
新建vue.config.js

module.exports = {
    // 项目部署的基础路径
    // 我们默认假设你的应用将会部署在域名的根部,
    // 比如 https://www.my-app.com/
    // 如果你的应用时部署在一个子路径下,那么你需要在这里
    // 指定子路径。比如,如果你的应用部署在
    // https://www.foobar.com/my-app/
    // 那么将这个值改为 `/my-app/`
  /*这个是我存放在github在线预览的Reader项目*/

    // 将构建好的文件输出到哪里(或者说将编译的文件)
    outputDir: 'dist',

    // 放置静态资源的地方 (js/css/img/font/...)
    assetsDir: 'static',

    // 用于多页配置,默认是 undefined
    pages: {
        index: {
            // 入口文件
            entry: 'src/main.js',  /*这个是根入口文件*/
            // 模板文件
            template: 'public/index.html',
            // 输出文件
            filename: 'index.html',
            // 页面title
            title: 'Index Page'
        },
        // 简写格式
        // 模板文件默认是 `public/subpage.html`
        // 如果不存在,就是 `public/index.html`.
        // 输出文件默认是 `subpage.html`.
        subpage: 'src/main.js'    /*注意这个是*/
    },

    // 是否在保存的时候使用 `eslint-loader` 进行检查。
    // 有效的值:`ture` | `false` | `"error"`
    // 当设置为 `"error"` 时,检查出的错误会触发编译失败。
    lintOnSave: true,

    // 使用带有浏览器内编译器的完整构建版本
    // 查阅 https://cn.vuejs.org/v2/guide/installation.html#运行时-编译器-vs-只包含运行时
    runtimeCompiler: false,

    // babel-loader 默认会跳过 node_modules 依赖。
    // 通过这个选项可以显式转译一个依赖。
    transpileDependencies: [/* string or regex */],

    // 是否为生产环境构建生成 source map?
    productionSourceMap: true,

    // 调整内部的 webpack 配置。
    // 查阅 https://github.com/vuejs/vue-docs-zh-cn/blob/master/vue-cli/webpack.md
    chainWebpack: () => {},
    configureWebpack: () => {},

    // CSS 相关选项
    css: {
        // 将组件内的 CSS 提取到一个单独的 CSS 文件 (只用在生产环境中)
        // 也可以是一个传递给 `extract-text-webpack-plugin` 的选项对象
        extract: true,

        // 是否开启 CSS source map?
        sourceMap: false,

        // 为预处理器的 loader 传递自定义选项。比如传递给
        // sass-loader 时,使用 `{ sass: { ... } }`。
        loaderOptions: {},

        // 为所有的 CSS 及其预处理文件开启 CSS Modules。
        // 这个选项不会影响 `*.vue` 文件。
        modules: false
    },

    // 在生产环境下为 Babel 和 TypeScript 使用 `thread-loader`
    // 在多核机器下会默认开启。
    parallel: require('os').cpus().length > 1,

    // PWA 插件的选项。
    // 查阅 https://github.com/vuejs/vue-cli/tree/dev/packages/@vue/cli-plugin-pwa
    pwa: {},

    // 配置 webpack-dev-server 行为。
    devServer: {
        open: process.platform === 'darwin',
        host: '0.0.0.0',
        port: 8080,
        https: false,
        hotOnly: false,
        // 查阅 https://github.com/vuejs/vue-docs-zh-cn/blob/master/vue-cli/cli-service.md#配置代理
        proxy:{
            '/api':{
                target:'http://localhost:9000',
                changeOrigin:true,
                secure:false,
                // ws: true,
                pathRewrite:{
                    '^/api':'/static/mock'// 请求数据路径别名,这里是注意将static/mock放入public文件夹
                }
            }
        },
        before: app => {}
    },

    // 三方插件的选项
    pluginOptions: {
        // ...
    }
}

config目录下的index.js

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

const path = require('path')

module.exports = {
  dev: {
    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: './',
    proxyTable: {},

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

    // Use Eslint Loader?
    // If true, your code will be linted during bundling and
    // linting errors and warnings will be shown in the console.
    useEslint: false,
    // If true, eslint errors and warnings will also be shown in the error overlay
    // in the browser.
    showEslintErrorsInOverlay: false,

    /**
     * Source Maps
     */

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

    // CSS Sourcemaps off by default because relative paths are "buggy"
    // with this option, according to the CSS-Loader README
    // (https://github.com/webpack/css-loader#sourcemaps)
    // In our experience, they generally work as expected,
    // just be aware of this issue when enabling this option.
    cssSourceMap: false
  },

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

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

    /**
     * You can set by youself according to actual condition
     * You will need to set this if you plan to deploy your site under a sub path,
     * for example GitHub pages. If you plan to deploy your site to https://foo.github.io/bar/,
     * then assetsPublicPath should be set to "/bar/".
     * In most cases please use '/' !!!
     */
    assetsPublicPath: './',

    /**
     * Source Maps
     */

    productionSourceMap: false,
    // 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 || false,

    // `npm run build:prod --generate_report`
    generateAnalyzerReport: process.env.npm_config_generate_report || false
  }
}

其实还不明白这两个的区别。
输入:

npm run build prod
生成dist
在这里插入图片描述

后端

jar包:
在这里插入图片描述
打开后端项目(IDEA)先点击clean再点击package
生成
在这里插入图片描述
发现 问题:(1)服务器的浏览器输入8080一片空白,
解决:只把dist复制到了ROOT目录下,但应该把index.html和static复制到下面才行,重新改为:
在这里插入图片描述

打开8080显示登陆页面:
在这里插入图片描述

问题(2)点击登录没反应,进不去
解决:
1.
修改vue.config.js

  proxy:{
            '/api':{
                target:'http://localhost:9000',
                changeOrigin:true,
                secure:false,
                // ws: true,
                pathRewrite:{
                    '^/api':'/static/mock'// 请求数据路径别名,这里是注意将static/mock放入public文件夹
                }
            }
        },

(后端springboot的application.yml中端口是9000:

server:
port: 9000
)

再次输入npm run build prod
粘贴index.html和static

2.一定要记得启动jar包 !!!!!
启动jar的方式是双击这个文件:
在这里插入图片描述
现在点击登录有反应了:
在这里插入图片描述
下一个问题是数据库的数据在服务器上还显示不出来,留待解决。

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Linux系统上打包部署springboot+vue项目的步骤如下: 1. 首先,你需要拉取git仓库的代码。复制git仓库的地址,并在Linux系统中使用命令拉取代码。\[1\] 2. 接下来,你需要打包Java项目。进入项目的目录,执行打包命令,生成一个jar包。你可以使用命令`java -jar springboot-affair-0.0.1-SNAPSHOT.jar`来运行打包好的Java项目。\[3\] 3. 然后,你需要部署前端vue项目。同样进入项目的目录,执行打包命令,生成前端的静态文件。将生成的静态文件部署到Nginx服务器上。 4. 在部署之前,确保Nginx、MySQL、Redis和MinIO已经启动。你可以使用相应的命令来启动这些服务。 5. 最后,访问你的项目。通过浏览器访问Nginx服务器的地址,即可查看部署好的springboot+vue项目。 总结起来,你需要拉取代码,打包Java项目部署前端项目启动Nginx、MySQL、Redis和MinIO,然后访问项目即可。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* *3* [Linux——在Linux系统上打包部署springboot+vue项目,nginx+mysql+redis+minio](https://blog.csdn.net/weixin_56039103/article/details/126173205)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [使用docker部署springboot+vue项目](https://blog.csdn.net/Ruhoney908/article/details/131024801)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值