若依项目linux部署

1.后台部署


bin/package.bat 在项目的目录下执行
然后会在项目下生成 target文件夹包含 war 或jar (多模块生成在ruoyi-admin)

1、jar部署方式

使用命令行执行:java –jar ruoyi.jar 或者执行脚本:bin/run.bat
后台运行部署 nohup java -jar ruoyi.jar 2>1 &
改动过后,记得clear

2、war部署方式

pom.xml packaging修改为war 放入tomcat服务器webapps

打jar包

第一步。cd到ruoyi下面,打包jar包

mvn package

完成之后,发现多了个target文件夹,里面放的ruoyi.jar,即为所得

打包war包的方式(alternative)

1.需要打开rom.xml文件,修改配置。把

	<groupId>com.ruoyi</groupId>
	<artifactId>ruoyi</artifactId>
	<version>2.3.0</version>
	<packaging>jar</packaging>

改成:

<packaging>war</packaging>

plus:打完jar包,再打war包。记得:

mvn clean  //先清除
mvn package //在打包
Tomcat配置

修改server.xml,Host节点下添加

<Context docBase="" path="/" reloadable="true" source=""/>

dist目录的文件夹下新建WEB-INF文件夹,并在里面添加web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
        http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
        version="3.1" metadata-complete="true">
     <display-name>Router for Tomcat</display-name>
     <error-page>
        <error-code>404</error-code>
        <location>/index.html</location>
    </error-page>
</web-app>

提示
SpringBoot去除内嵌tomcat

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
	<exclusions>
		<exclusion>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
		</exclusion>
	</exclusions>
</dependency>
		
<!-- 单应用排除内置tomcat -->		
<exclusions>
	<exclusion>
		<artifactId>spring-boot-starter-tomcat</artifactId>
		<groupId>org.springframework.boot</groupId>
	</exclusion>
</exclusions>
2. 前端部署

以下为前端运行配置

# 进入项目目录
cd ruoyi-ui

# 安装依赖
npm install

# 强烈建议不要用直接使用 cnpm 安装,会有各种诡异的 bug,可以通过重新指定 registry 来解决 npm 安装速度慢的问题。
npm install --registry=https://registry.npm.taobao.org

# 本地开发 启动项目
npm run dev
当项目开发完毕,只需要运行一行命令就可以打包你的应用

# 打包正式环境
npm run build:prod

# 打包预发布环境
npm run build:stage

构建打包成功之后,会在根目录生成 dist 文件夹,里面就是构建打包好的文件,通常是 ***.js 、***.css、index.html 等静态文件。

通常情况下 dist 文件夹的静态文件发布到你的 nginx 或者静态服务器即可,其中的 index.html 是后台服务的入口页面。

outputDir 提示

如果需要自定义构建,比如指定 dist 目录等,则需要通过 config (opens new window)的 outputDir 进行配置。

publicPath 提示

部署时改变页面js 和 css 静态引入路径 ,只需修改 vue.config.js 文件资源路径即可。

publicPath: './' //请根据自己路径来配置更改
export default new Router({
  mode: 'hash', // hash模式
})
环境变量

所有测试环境或者正式环境变量的配置都在 .env.development (opens new window)等 .env.xxxx文件中。

它们都会通过 webpack.DefinePlugin 插件注入到全局。

注意!!!

环境变量必须以VUE_APP_为开头。如:VUE_APP_API、
VUE_APP_TITLE

你在代码中可以通过如下方式获取:

console.log(process.env.VUE_APP_xxxx)
Nginx配置

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

		location / {
            root   /home/ruoyi/projects/ruoyi-ui;
			try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }
		
		# 如果是测试环境则使用/stage-api/
		# 后台服务代理
		location /prod-api/{ 
			proxy_set_header Host $http_host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header REMOTE-HOST $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_pass http://localhost:8080/;
		}

		# 图片路径代理
		location /profile/ {
		    # 方式一:指向地址
		    proxy_pass http://localhost:8088/profile/; 
		}

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

运行命令

/usr/local/nginx/sbin/nginx -s reload
常见问题

如果使用Mac 需要修改application.yml文件路径profile
如果使用Linux 提示表不存在,设置大小写敏感配置在/etc/my.cnf 添加lower_case_table_names=1,重启MYSQL服务
如果提示当前权限不足,无法写入文件请检查profile是否可读可写,或者无法访问此目录

图片上传成功不能显示

文件上传成功后,请求访问后台地址会根据profile进行匹配,需要自己配置nginx代理,参考如下。

location /profile/ {
    # 方式一:指向地址
    proxy_pass http://127.0.0.1:9999/profile/; 
}
location /profile/
{
    # 方式二:指向目录,对应后台`application.yml`中的`profile`配置
    alias /home/ruoyi/uploadPath/;
}
前端如何配置后端接口

对于特殊情况,需要直接调用后台接口或者指定域名可以修改.env.production文件VUE_APP_BASE_API属性

# 后端接口地址
VUE_APP_BASE_API = '//localhost:8080'
图片上传成功不能显示

在这里插入图片描述

参考文档

https://doc.ruoyi.vip/ruoyi-vue/
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值