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

前后端分离Nginx

背景

旧的部署方式是将前端代码打包进后端包的resource

 server {listen       80;listen       443 ssl;server_name  xxx.test.com;location / {proxy_pass  http://xxx.test.com;}
}

后端:https:// xxx.test.com/simcard/querySimcard
前端:https:// xxx.test.com/#/app/number/card-query/list

问题

前端的代码是作为后端的一部分,无法独立发布

改造要求

1.保持后端接口访问路由不变
2.没有额外域名提供
3.尽量不改动或者少量改动现有代码

不满足要求(常规)

 server {listen       80;listen       443 ssl;server_name  xxx.test.com;location / {root /usr/local/nginx/html/test-html/test-web;index index.html index.htm;}location /api {proxy_pass  http://xxx.test.com;}
}

缺点

1.导致后端访问接口路由改变

满足要求方案

1.后端增加一个访问入口

@Controller
public class IndexController {@GetMapping(value = { "/", "/index", "/index.html" })public void index(HttpServletResponse response) throws IOException {response.sendRedirect("http://xxx.test.com/index.html");}
}

2.Nginx代理前后端

 server {listen       80;listen       443 ssl;server_name  xxx.test.com;# 前端静态资源    location /dist/ {alias /usr/local/nginx/html/test-html/test-web;autoindex on;            }# 前端index页面,通过后端入口访问转发location /index.html {alias /usr/local/nginx/html/test-html/test-web;index index.html index.htm;}# 后端接口代理location / {proxy_pass  http://xxx.test.com;}
}
http://www.lryc.cn/news/392944.html

相关文章:

  • 【简单讲解下Tauri】
  • mac上挂载linux目录
  • Linux系统的服务——以Centos7为例
  • Numpy矩阵运算
  • Spring容器Bean之XML配置方式
  • 【Rust入门】生成随机数
  • 普通Java工程如何在代码中引用docker-compose.yml中的environment值
  • 微观特征轮廓尺寸测量:光学3D轮廓仪、共焦显微镜与台阶仪的应用
  • Rust开发环境搭建
  • 图文识别0难度上手~基于飞浆对pdf简易ocr并转txt
  • FFmpeg常用命令手册
  • CTF入门知识点
  • Leetcode 完美数
  • springboot中的定时任务编写
  • 第100+14步 ChatGPT学习:R实现随机森林分类
  • C#面 :ASP.Net Core中有哪些异常处理的方案?
  • 论文辅导 | 基于多尺度分解的LSTM⁃ARIMA锂电池寿命预测
  • 开关阀(4):对于客户技术要求信息的识别
  • Python统计实战:时间序列分析之二阶曲线预测和三阶曲线预测
  • Drools开源业务规则引擎(三)- 事件模型(Event Model)
  • 智慧校园行政办公升级,日程监控不可或缺
  • RedHat运维-Linux SSH基础3-sshd守护进程
  • 医院产科信息化管理系统源码,智慧产科管理系统,涵盖了从孕妇到医院初次建档、历次产检、住院分娩、统计上报到产后42天全部医院服务的信息化管理。
  • Softmax作为分类任务中神经网络输出层的优劣分析
  • 404白色唯美动态页面源码
  • 细说MCU的ADC模块单通道连续采样的实现方法
  • H2 Database Console未授权访问漏洞封堵
  • 基于java+springboot+vue实现的药店管理系统(文末源码+Lw)285
  • 网络爬虫基础
  • js数组方法归纳——push、pop、unshift、shift