ruoyi框架前端vue部署生产环境教程

前端有子目录,后端有项目名称,请看第3种

第1种

前端nginx没有子目录,后端也没有访问的项目名。这种是最简单的。

vue.config.js

只需要修改target中的IP和端口,就是后端访问的IP和端口

# vue.config.js
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://192.168.1.120:8080`,
        // 生产环境--------修改自己的IP和端口
        target: `http://192.168.100.110:8080`,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: ''
        }
      }
    },
    disableHostCheck: true
  },

 .env.production

# .env.production
# 删除里面的/prod-api
VUE_APP_BASE_API = ''

操作

修改了上面的配置后,直接输入npm run build:prod,等待编译完成。然后把dist文件中的所有文件复制上传到nginx/html文件夹下面,然后启动nginx即可。

结束

---------------------------------

---------------------------------

---------------------------------

第2种

前端nginx没有子目录,后端有自定义访问的项目名,也就是项目访问的前缀。

vue.config.js

只需要修改target中的IP和端口,追加了后端访问的项目名。下面的demo中的工程名称叫做usersystem

# vue.config.js
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://192.168.1.120:8080/usersystem`,
        // 生产环境--------修改自己的IP和端口,项目名称
        target: `http://192.168.100.110:8080/usersystem`,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: ''
        }
      }
    },
    disableHostCheck: true
  },

 .env.production

# .env.production

VUE_APP_BASE_API = '/usersystem'

 nginx.conf

 
 
#user  nobody;
worker_processes  1;
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
    # 文件大小限制,默认1m
    client_max_body_size     50m;
    client_header_timeout    1m;
    client_body_timeout      1m;
    proxy_connect_timeout    60s;
    proxy_read_timeout      1m;
    proxy_send_timeout      1m;
    # websocket需要增加该配置
    map $http_upgrade $connection_upgrade {
      default keep-alive;
      'websocket' upgrade;
  }
 
    #gzip  on;
 
    upstream user_server_name{
        server 192.168.1.110:8080;
    }
    
    server {
        listen 80;
        server_name user.test.com;
        
        location / {
            index index.html index.htm;
            root /usr/nginx/html;
            try_files $uri $uri/ /index.html;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        error_page 404 /index.html;
        location = /index.html {
        	root /usr/nginx/html;
        }
        # 后台访问地址
        location /usersystem/ {
            # enterprise wechat test
            add_header X-Content-Type-Options nosniff;
            proxy_set_header X-scheme $scheme;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            # 注意必须设置 Host,否则使用 Java Client 无法正常访问 MinIO
            proxy_set_header Host $http_host;
            proxy_set_header X-Nginx-Proxy true;
            proxy_hide_header X-Powered-By;
            proxy_hide_header Vary;
            client_max_body_size 2048m; 
            proxy_pass http://user_server_name;
            # 重复提交情况
            proxy_next_upstream off;
            proxy_read_timeout 600;
			proxy_send_timeout 600;
            proxy_connect_timeout 600;
        }
 
   
    }
 
    server {
        listen       80;
        # 自己需要监听的域名
        server_name user.test.com;
        #将请求转成https
        rewrite ^(.*)$ https://$host$1 permanent;
        
    }
 
 
}

操作

修改了上面的配置后,直接输入npm run build:prod,等待编译完成。然后把dist文件中的所有文件复制上传到nginx/html文件夹下面,然后启动nginx即可。

结束

---------------------------------

---------------------------------

---------------------------------

第3种

前端需要部署在nginx的子目录中,后端有访问的项目名。

vue.config.js

只需要修改target中的IP和端口,就是后端访问的IP和端口

// vue.config.js

  

// 前端部署在nginx/html/usersystemWeb文件夹里面,也就是前端子目录名称
publicPath: process.env.NODE_ENV === "production" ? "/usersystemWeb/" : "/",

// 默认dist
outputDir: 'usersystemWeb',

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://192.168.1.120:8080/usersystem`,
        // 生产环境--------修改自己的IP和端口,项目名称
        target: `http://192.168.100.110:8080/usersystem`,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: ''
        }
      }
    },
    disableHostCheck: true
  },

 .env.production

# .env.production

VUE_APP_BASE_API = '/usersystem'

router/index.js 

// router/index.js

export default new Router({
// 在这里增加前端子目录的名称
  base:'/usersystemWeb/',
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

public/index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <!-- 在这里增加自己的子目录名称 -->
    <meta base="/aiot/">

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <link rel="icon" href="<%= BASE_URL %>logo.ico">
    <title><%= webpackConfig.name %></title>
    <!--[if lt IE 11]><script>window.location.href='/html/ie.html';</script><![endif]-->
	  <style>
   
  </style>
  </head>
  <body>
    <div id="app">
	    <div id="loader-wrapper">
		    <div id="loader"></div>
		    <div class="loader-section section-left"></div>
		    <div class="loader-section section-right"></div>
		    <!-- <div class="load_title">正在加载系统资源,请耐心等待</div> -->
        </div>
	</div>
 
  </body>
</html>

nginx.conf

 
 
#user  nobody;
worker_processes  1;
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
    # 文件大小限制,默认1m
    client_max_body_size     50m;
    client_header_timeout    1m;
    client_body_timeout      1m;
    proxy_connect_timeout    60s;
    proxy_read_timeout      1m;
    proxy_send_timeout      1m;
    # websocket需要增加该配置
    map $http_upgrade $connection_upgrade {
      default keep-alive;
      'websocket' upgrade;
  }
 
    #gzip  on;
 
 
    upstream websocket_name{
        server 192.168.1.15:11108;
    }
    upstream user_server_name{
        server 192.168.1.110:8080;
    }
    
    server {
        listen 80;
        server_name user.test.com;
        
        location ^~/usersystemWeb {
            # 前端子目录文件夹名称
            alias /usr/local/nginx/html/usersystemWeb;
            try_files $uri $uri/ /index.html;
            index index.html;
        }
        location / {
            index index.html index.htm;
            root /usr/local/nginx/html/usersystemWeb;
            # 下面这句话可以解决vue打包部署后,页面刷新报404的问题
            try_files $uri $uri/ /index.html;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        error_page 404 /index.html;
        location = /index.html {
        	root /usr/local/nginx/html/usersystemWeb;
        }
        # 后台访问地址
        location /usersystem/ {
            # enterprise wechat test
            add_header X-Content-Type-Options nosniff;
            proxy_set_header X-scheme $scheme;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            # 注意必须设置 Host,否则使用 Java Client 无法正常访问 MinIO
            proxy_set_header Host $http_host;
            proxy_set_header X-Nginx-Proxy true;
            proxy_hide_header X-Powered-By;
            proxy_hide_header Vary;
            client_max_body_size 2048m; 
            proxy_pass http://user_server_name;
            # 重复提交情况
            proxy_next_upstream off;
            proxy_read_timeout 600;
			proxy_send_timeout 600;
            proxy_connect_timeout 600;
        }
 
  
 
        # 重点在这里,websocket后面没有斜杠,和其它项目的区别
        location /websocket {
            proxy_pass http://websocket_name;
            proxy_read_timeout 300s;
            proxy_send_timeout 300s;
            proxy_redirect off;
            proxy_set_header Host $host:5052;
            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;
            #升级http1.1到 websocket协议
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection  $connection_upgrade;
        }
   
    }
 
    server {
        listen       80;
        # 自己需要监听的域名
        server_name user.test.com;
        #将请求转成https
        rewrite ^(.*)$ https://$host$1 permanent;
        
    }
 
 
}

操作

修改了上面的配置后,直接输入npm run build:prod,等待编译完成。然后把usersystemWeb文件中的所有文件复制上传到nginx/html/usersystemWeb文件夹下面,然后启动nginx即可。

nginx安装教程

# 安装nginx的依赖包
yum -y install gcc gcc- c++ pcre-devel openssl-devel wget

# 自己创建文件夹
cd /opt/myNginx

# 下载nginx安装
wget http://nginx.org/download/nginx-1.12.2.tar.gz 

# 解压nginx-1.12.2的压缩包
tar xf nginx-1.12.2.tar.gz

# 进入nginx-1.12.2 文件目录
cd nginx-1.12.2 

# 配置检测环境、文件目录在/usr/local/nginx这是需要SSL的命令
# 如果不需要就执行./configure --prefix=/usr/local/nginx命令
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

# 编译
make && make install

# 制作软连接
ln -sv /usr/local/nginx/sbin/nginx /usr/bin/nginx

# 修改环境变量
vim /etc/profile

# 按下i键,在profile文件末尾,加上下面的代码
PATH=$PATH:/usr/local/nginx/sbin

# 按下esc键,然后输入:wq来退出
# 刷新配置文件
source /etc/profile

nginx启动停止命令

# nginx-cmd.sh

# 每次修改配置文件需要重新启动,第一次启动必须使用start命令,不能使用restart命令
# 启动
# sh /usr/local/nginx/nginx-cmd.sh start
# 停止
# sh /usr/local/nginx/nginx-cmd.sh stop
# 重启
# sh /usr/local/nginx/nginx-cmd.sh restart

#!/bin/bash
# Nginx可执行文件路径 别忘了换成你自己安装的路径
NGINX_PATH="/usr/local/nginx/sbin/nginx"

start() {
    echo "Starting Nginx..."
    $NGINX_PATH
}

stop() {
    echo "Stopping Nginx..."
    $NGINX_PATH -s stop
}

restart() {
    echo "Restarting Nginx..."
    $NGINX_PATH -s reload
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        restart
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac

exit 0

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
ruoyi-flowable-plus前端采用的是Vue.js框架,并通过npm进行依赖管理和构建。要部署ruoyi-flowable-plus前端,可以按照以下步骤进行操作: 1. 下载并安装Node.js:前端项目需要依赖Node.js环境。前往Node.js官网(https://nodejs.org/)下载适合您操作系统的安装程序,并进行安装。 2. 安装依赖:使用命令行进入ruoyi-flowable-plus前端项目的根目录,在命令行中运行以下命令安装项目所需的依赖项: ```shell npm install ``` 3. 修改后端接口地址:在src目录下找到config目录中的index.js文件,修改其中的`baseApi`字段为实际的后端接口地址。 4. 构建项目:运行以下命令进行项目构建: ```shell npm run build ``` 执行该命令后,会在项目根目录下生成一个dist文件夹,该文件夹中包含了构建好的前端项目代码。 5. 部署到服务器:将生成的dist文件夹中的所有文件拷贝到您的服务器上,可以选择您喜欢的Web服务器软件(例如Nginx、Apache等)进行部署。将文件放置在服务器指定的目录下,如Nginx的默认目录是/usr/share/nginx/html。 6. 配置服务器:根据您选择的Web服务器软件,进行相应的配置,例如在Nginx中配置反向代理,将前端路由请求转发到index.html文件。 7. 启动前端:完成上述步骤后,启动Web服务器并访问服务器地址,就可以在浏览器中正常访问ruoyi-flowable-plus前端页面了。 注意:在部署前,确保已经正确安装并配置好后端服务器,并且可以通过后端接口正常访问数据。前端和后端需要进行相应的配置以实现数据交互。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

renkai721

谢谢您的打赏!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值