API 网关与反向代理 [英] API gateway vs. reverse proxy

查看:115
本文介绍了API 网关与反向代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了处理微服务架构,它通常与反向代理(例如 nginx 或 apache httpd)一起使用,并用于横切关注点的实现 使用 API 网关模式.有时反向代理会做 API 网关的工作.

In order to deal with the microservice architecture, it's often used alongside a Reverse Proxy (such as nginx or apache httpd) and for cross cutting concerns implementation API gateway pattern is used. Sometimes Reverse proxy does the work of API gateway.

很高兴看到这两种方法之间的明显差异.看起来使用 API 网关的潜在好处是调用多个微服务并聚合结果.所有其他职责 API 网关可以使用反向代理来实现.如:

It will be good to see clear differences between these two approaches. It looks like the potential benefit of API gateway usage is invoking multiple microservices and aggregating the results. All other responsibilities of API gateway can be implemented using Reverse Proxy. Such as:

  • 身份验证(可以使用 Nginx LUA 脚本完成);
  • 运输安全.它本身就是反向代理任务;
  • 负载均衡
  • ...

因此基于此有几个问题:

So based on this there are several questions:

  1. 同时使用 API 网关和反向代理是否有意义(例如请求 -> API 网关 -> 反向代理(nginx) -> 具体微服务)?在什么情况下?
  2. 可以使用 API 网关实现而不能通过反向代理实现(反之亦然)的其他区别是什么?

推荐答案

如果您意识到它们不是相互排斥的,那么考虑它们会更容易.将 API 网关视为特定类型的反向代理实现.

It is easier to think about them if you realize they aren't mutually exclusive. Think of an API gateway as a specific type reverse proxy implementation.

关于您的问题,通常会看到两者结合使用,其中 API 网关被视为位于反向代理后面的应用程序层,用于负载平衡和健康检查.一个例子是类似于 WAF 三明治架构的东西,其中您的 Web 应用程序防火墙/API 网关被反向代理层夹在中间,一个用于 WAF 本身,另一个用于它与之通信的各个微服务.

In regards to your questions, it is not uncommon to see the both used in conjunction where the API gateway is treated as an application tier that sits behind a reverse proxy for load balancing and health checking. An example would be something like a WAF sandwich architecture in that your Web Application Firewall/API Gateway is sandwiched by reverse proxy tiers, one for the WAF itself and the other for the individual microservices it talks to.

关于差异,它们非常相似.这只是命名法.当您进行基本的反向代理设置并开始添加更多部分(例如身份验证、速率限制、动态配置更新和服务发现)时,人们更有可能将其称为 API 网关.

Regarding the differences, they are very similar. It's just nomenclature. As you take a basic reverse proxy setup and start bolting on more pieces like authentication, rate limiting, dynamic config updates, and service discovery, people are more likely to call that an API gateway.

这篇关于API 网关与反向代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆