绕过网关缓存
默认情况下,所有的请求都经过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;
# 匹配以 / 开头 ,()代表分组 ,. 代表任意,*代表个数,匹配