JAVA前后端分离项目Linux服务器部署

项目部署所需基本环境:
Mysql5.7或以上
jdk1.8或以上
nginx

一、打包前端项目

1、打包好的前端项目,生成一个dist文件

2、复制文件夹内所有的文件

3、如图,将前端打包好的项目全部添加到后端项目的xxxx/src/main/resources/static目录下(根据自己的项目决定,非必要)

二、打包后端项目

1、删除target文件夹(确保检测到更新)

2、clean

3、package

4、完成上述步骤后,将打包后生成的jar包,上传至服务器指定目录。

5、将前端打好的包(dist文件夹)放在服务器指定目录。如/home/xxx/web/dist(dist可重命名)

6、修改nginx.conf文件

编辑.conf文件:vim /usr/local/nginx/conf/nginx.conf (配置文件路径以你的为准)

添加如下内容

server {
    listen       9898;
    server_name  localhost;

   location / {
      # 静态文件地址
    root   /home/xxx/web/dist;(前端包所在位置)
    try_files $uri $uri/ /index.html;
    index  index.html index.htm;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection  "upgrade";
    }

location /demo/{
    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_set_header Upgrade $http_upgrade;
    proxy_set_header Connection  "upgrade";
    proxy_pass http://localhost:8748/xxx-api/;(改为你后端接口地址   http://xxxx/xxx-api/)
}

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

7、启动服务

(方式一:命令启动)

nohup java -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5098 -Xms1024m -Xmx1024m  -Duser.timezone=GMT+08 xxx.jar(xxx:你的jar包)  --nacos.address=localhost:8848 > ./xxx.out (xxx:日志输出文件) 2>&1 &

(方式二:脚本启动)

1、在jar包目录创建.sh脚本文件:touch start.sh

2、编辑脚本内容:vi start.sh

3、将如下启动命令复制进去,wq保存

#!/bin/bash
source /etc/profile


echo "Stopping xxx"(xxx:你的项目名)
pid=`ps -ef | grep chrtc-imaps.jar | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]; then
    kill -9 $pid
    sleep 2
fi
echo "Starting xxx"(xxx:你的项目名)
cd /home/xxx/jar/ (xxx:你的jar包目录)
nohup java -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5098 -Xms1024m -Xmx1024m  -Duser.timezone=GMT+08 xxx.jar(xxx:你的jar包)  --nacos.address=localhost:8848 > ./xxx.out (xxx:日志输出文件) 2>&1 &
echo "Starting xxx"(xxx:你的项目名)

tail -f xxx.out (xxx:你项目日志输出文件,可提前在jar包目录创建)

8、输入你在nginx.conf配置的服务器访问地址:localhost:8748 (ip:端口号),项目部署成功。


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值