当前位置: 首页 > news >正文

发布vue项目、nginx配置及问题场景(history)

场景

  1. 我想使用一个nginx配置多个程序页面
  2. 使用alias时刷新和退出时会404,或者退出路由不对

实现

在env环境变量中配置 前置路径

VUE_APP_PATH = '/'
VUE_APP_PATH = '/middle-platform-manager/'

router /index.js(路由配置文件)

export default new Router({mode: 'history', // 去掉url中的#scrollBehavior: () => ({ y: 0 }),routes: constantRoutes,base: process.env.VUE_APP_PATH  # 加入环境信息
})

修系统中的location.href 连接

location.href = process.env.VUE_APP_PATH + 'index'

vue.config.js

  publicPath: process.env.VUE_APP_PATH,

nginx配置

server {listen       80;listen  [::]:80;server_name  localhost;#access_log  /var/log/nginx/host.access.log  main;location /prod-api/ {proxy_pass http://middle-platform-server:8080/;charset utf-8;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;#add_header Content-Type 'text/html; charset=utf-8';}# location / {# 	alias   /usr/share/nginx/html/;# 	index  index.html index.htm;# }location / {set $flag 0;#获取url完整请求set $URL  $host$request_uri;if ($URL ~ "/middle-platform-manager/"){set $flag 1;root /usr/share/nginx/html/middle-platform-manager/;}if ($flag = 0){root  /usr/share/nginx/html/;}index index.html index.htm;autoindex on;}location /middle-platform-manager {alias /usr/share/nginx/html/middle-platform-manager/;try_files $uri $uri/ /index.html;autoindex on;}#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   /usr/share/nginx/html;# }# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# 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;#}
}

之后遇到的其他的问题

因为用的是ruoyi的框架,改完后,点击登录,发现还是匹配不上,后面排查发现是因为login.vue登录成功跳转的时候路径变成了 ‘/middle-platform-manager//home/index’, 中间多了个 ‘/‘导致nginx匹配不上,需要再push路径的时候,处理router路由开头的’/’,部署后就完美解决了,退出、刷新、等了都没问题了

http://www.xdnf.cn/news/1476775.html

相关文章:

  • 服务器内存和普通计算机内存在技术方面有什么区别?
  • 前端入门——案例一:登录界面设计(html+css+js)
  • 【xss基本介绍】
  • 风电塔筒有毒有害气体监测控制系统
  • Maimo-AI驱动的行业研究工作平台
  • 理想汽车智驾方案介绍 4 World model + 强化学习重建自动驾驶交互环境
  • PostgreSQL与Greenplum常见连接客户端
  • 详解 Java 中的 CopyOnWriteArrayList
  • [光学原理与应用-420]:非线性光学 - 线性思维与非线性思维
  • kafka集群的安装与部署
  • 多种同类型日志采集中,字段归一化处理方案
  • Zynq设备与电脑相连方式
  • 阿里云对象存储OSS的使用
  • 【ComfyUI】深度 ControlNet 深度信息引导生成
  • 从Java全栈到Vue3实战:一次真实面试中的技术探索
  • MATLAB2025-安装Embedded Code Support Pacjage for STM32 Processors
  • 07-任务调度器的挂起和恢复
  • 【golang长途旅行第38站】工厂模式
  • 【Linux基础】Linux系统管理:GPT分区实践详细操作指南
  • 深度学习--自然语言预处理--- Word2Vec
  • 网络通信 IO 模型学习总结基础强化
  • 前缀和、子矩阵的和;差分、差分矩阵
  • 交换机详细
  • 软考 系统架构设计师系列知识点之杂项集萃(141)
  • 【LeetCode热题100道笔记】二叉树的层序遍历
  • RTU(远程终端单元)​​ 和 ​​PLC(可编程逻辑控制器)
  • 《AC影》正史模式引争议 育碧回应希望激发历史兴趣
  • 【CF】Day139——杂题 (绝对值变换 | 异或 + 二分 | 随机数据 + 图论)
  • 《用 Python 构建并发 API 爬虫:从基础到高性能实战》
  • Python爬虫实战:研究Axis Artist模块,构建电商数据采集和分析系统