• 若依前后端分离项目部署


    部署方式

    前端vue打dist,后端打jar包,并用nginx代理。

    前端打包

    设置vue.config.js的devServer.proxy.target

    devServer: {
        host: '0.0.0.0',
        port: port,
        open: true,
        proxy: {
          // detail: https://cli.vuejs.org/config/#devserver-proxy
          [process.env.VUE_APP_BASE_API]: {
            target: `http://localhost:8080/`,//后端地址,后端用的是8080端口
            changeOrigin: true,
            pathRewrite: {
              ['^' + process.env.VUE_APP_BASE_API]: ''
            }
          }
        },
        disableHostCheck: true
      },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    进入ruoyi-ui文件夹

    npm run build:stage 部署测试环境时打包
    npm run build:prod   部署生产环境时打包
    
    • 1
    • 2

    生成dist文件夹

    后端打包

    打开application.yml确认后端端口
    在这里插入图片描述

    server:
      # 服务器的HTTP端口,默认为8080
      port: 8080
    
    • 1
    • 2
    • 3

    使用maven打包

    mvn clean package -Ptest -Dmaven.test.skip=true
    
    • 1

    生成target文件夹
    target文件夹下的ruoyi-admin.jar就是后端打包文件了

    配置nginx

    编辑nginx.conf如下

    
    #user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
        server {
            listen       80;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
              #前端项目在服务器部署的位置
    		  root   C:\Users\Administrator\Desktop\dist;
    		  index index.html index.htm;
    		  client_max_body_size 300m;
    		}
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            location /stage-api/ { 
            #vue前端所有接口都会根据打包环境加上/stage-api/或/prod-api/前缀(看你是npm run build:stage还是:prod),然后代理到后端接口服务,下面的rewrite也要对应
                rewrite ^/stage-api/(.*)$ /$1 break;
                proxy_pass http://127.0.0.1:8080; #访问后端的地址
            }
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ \.php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /\.ht {
            #    deny  all;
            #}
        }
    
    
        # another virtual host using mix of IP-, name-, and port-based configuration
        #
        #server {
        #    listen       8000;
        #    listen       somename:8080;
        #    server_name  somename  alias  another.alias;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    
    
        # HTTPS server
        #
        #server {
        #    listen       443 ssl;
        #    server_name  localhost;
    
        #    ssl_certificate      cert.pem;
        #    ssl_certificate_key  cert.key;
    
        #    ssl_session_cache    shared:SSL:1m;
        #    ssl_session_timeout  5m;
    
        #    ssl_ciphers  HIGH:!aNULL:!MD5;
        #    ssl_prefer_server_ciphers  on;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122

    启动Nginx和jar包

    nohup java -Xms500m -Xmx500m -Xmn256m -Xss256k -server -XX:+HeapDumpOnOutOfMemoryError
     -jar -Dlogging.file=d:/user.log ruoyi-admin.jar  --server.port=8080 -verbose:class &
    
    • 1
    • 2

    -Xms500m -Xmx500m -Xmn256m -Xss256m 用来设置堆内存
    -server:服务器模式,在多个CPU时性能佳,启动慢但性能好,能合理管理内存
    在排查jar包冲突时,可以指定启动的-verbose:class 打印出启动的应用实际加载类的路径,来排查来源。
    -XX:+HeapDumpOnOutOfMemoryError:在堆溢出时保存快照
    –server.port=8080 指定端口
    d:/user.log是java运行jar包的日志

    我的jar包放在d盘根目录,若依还会生成应用日志在jar包目录下的home/ruoyi/logs
    在这里插入图片描述

    最后双击nginx.exe启动nginx就可以了

  • 相关阅读:
    在Windows平台编译OpenJdk8
    十年开发老手,深度解析企业用人标准为何越来越高?!
    Cron表达式的Js插件
    pnpm使用教程
    Vue3 快速入门和模板语法
    订单及其状态机的设计实现
    关于安卓SVGA浅尝(一)svgaplayer库的使用
    基于JAVA在线辅导答疑系统计算机毕业设计源码+系统+数据库+lw文档+部署
    新品上线 Naive Admin Tenant 开箱即用多租户开发框架
    Viewpager2嵌套RecyclerView导致的滑动卡顿
  • 原文地址:https://blog.csdn.net/xx1132856201/article/details/125442750