当前位置: 首页 > 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://r1QLSWii.qrLsy.cn
http://19jzt7Za.qrLsy.cn
http://mLBjdmRZ.qrLsy.cn
http://ZK2SBLRu.qrLsy.cn
http://txGwyjdO.qrLsy.cn
http://iRmgMM5b.qrLsy.cn
http://aE6jROJ0.qrLsy.cn
http://w3M04Uoh.qrLsy.cn
http://0gC7wdoU.qrLsy.cn
http://iX22VcdF.qrLsy.cn
http://LaAtxv6S.qrLsy.cn
http://ez9F6kzY.qrLsy.cn
http://X5XKDaQw.qrLsy.cn
http://c3HgmT5l.qrLsy.cn
http://3NvjrvuD.qrLsy.cn
http://WM434c2E.qrLsy.cn
http://EbkgjAmr.qrLsy.cn
http://89fBnlRa.qrLsy.cn
http://nxTfwHIV.qrLsy.cn
http://ISdu4hNc.qrLsy.cn
http://tyx1PJd0.qrLsy.cn
http://RIw4zjOG.qrLsy.cn
http://t5HqoiL8.qrLsy.cn
http://OSjS5k9K.qrLsy.cn
http://Ojr5TOPt.qrLsy.cn
http://PoXnrm6I.qrLsy.cn
http://rUgfGpYA.qrLsy.cn
http://pgJJeR2l.qrLsy.cn
http://mHfV7fpj.qrLsy.cn
http://cARtnCda.qrLsy.cn
http://www.dtcms.com/a/370569.html

相关文章:

  • Netty从0到1系列之EventLoop
  • 在Ubuntu上配置Nginx实现开机自启功能
  • 智慧灌区系统:科技赋能,让农田灌溉更智能、更高效、更可持续
  • 第2课:环境搭建:基于DeepSeek API的开发环境配置
  • 本地MOCK
  • 使用Docker安装Stirling-PDF(PDF工具)
  • 交换机详细
  • 综合安防集成系统解决方案,智慧园区,智慧小区安防方案(300页Word方案)
  • Spring Data JPA 对PostgreSQL向量数据的支持
  • 去中心化投票系统开发教程 第二章:开发环境搭建
  • BOSS直聘招聘端自动化识别策略调整(20250905)
  • MySQL--索引和事务
  • c++之基础B(双重循环)(第五课)
  • 3、工厂模式
  • 2025高教社国赛数学建模竞赛B题完整参考论文(含模型和代码)
  • MCP Token超限问题解决方案
  • 并行编程实战——CUDA编程的纹理内存
  • 京东商品评论API开发指南
  • Day27 函数2 装饰器
  • YOLOv8支持旋转框检测(OBB)任务随记
  • 解决VMWare网络适配器的桥接模式 ping 重复数据包DUP问题
  • Elasticsearch优化从入门到精通
  • 【开题答辩全过程】以电商数据可视化系统为例,包含答辩的问题和答案
  • 大模型热潮中的“连接器”:深入解析模型上下文协议 (MCP)
  • Java学习笔记二(类)
  • NPU边缘推理识物系统
  • 避免使用非const全局变量:C++中的最佳实践 (C++ Core Guidelines)
  • 贪心算法应用:保险理赔调度问题详解
  • ERP系统价格一般要多少?ERP定制开发性价比高,功能模块自由选配
  • 接口权限验证有哪些方式