第七章 上传图片服务优化和FastDFS(分布式文件系统)

绕过网关缓存

默认情况下,所有的请求都经过Zuul网关代理,默认会通过SpringMVC预先请求进行处理,缓存。普通请求并不会有什么影响,但是对于文件上传,就会造成不必要的网络负担。在高并发时,可能导致网络阻塞,Zuul网关不可用。这样我们的整个系统就瘫痪了。

所以,我们上传文件的请求需要绕过请求的缓存,直接通过路由来到达目标微服务。

Zuul is implemented as a Servlet. For the general cases, Zuul is
embedded into the Spring Dispatch mechanism. This lets Spring MVC be
in control of the routing. In this case, Zuul buffers requests. if
there is a need to go through Zull without buffering requests(for
example,for large file uploads), the Servlet is also installed outside
of the Spring Dispatcher. By default, the servlet has an address of
/zuul .This path can be changed with the zull.servlet.path porperty.

现在,查看页面的请求路径:
在这里插入图片描述

我们需要修改以/zuul为前缀,可以通过nginx的rewrite指令实现这一需求:

Nginx 提供 rewrite 指令,用于对地址进行重写,语法规则:
rewrite “用来匹配路径的正则” 重写后的路径 【指令】;

实例:

server {
   
	listen       80;
	server_name api.intell.com;
	
	proxy_set_header X-Forwarded-Host  $host;
	proxy_set_header X-Forwarded-Server  $host;
	proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;

# 匹配以 / 开头 ,()代表分组 ,. 代表任意,*代表个数,匹配
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值