简体   繁体   English

什么是Nginx / Web服务器术语中的“反向代理”和“负载平衡”?

[英]What is “Reverse Proxy” and “Load Balancing” in Nginx / Web server terms?

These are two phrases I hear about very often, mainly associated with Nginx. 这是我经常听到的两个短语,主要与Nginx有关。 Can someone give me a laymans defintion? 有人可以给我一个非专业人士的定义吗?

Definitions are often difficult to understand. 定义通常很难理解。 I guess you just need some explanation for their use case. 我想你只需要对他们的用例进行一些解释。

A short explanation is: load balancing is one of the functionalities of reverse proxy, and reverse proxy is one of the softwares that can do load balancing. 一个简短的解释是:负载平衡是反向代理的功能之一,而反向代理是可以进行负载平衡的软件之一。

And a long explanation is given below. 下面给出一个很长的解释。

For example a service of your company has customers in UK and German. 例如,贵公司的服务有英国和德国的客户。 Because the policy is different for these two countries, your company has two web servers, uk.myservice.com for UK and de.myservice.com for German, each with different business logic. 由于这两个国家的政策不同,贵公司有两个网络服务器,英国的uk.myservice.com和德语的de.myservice.com,每个都有不同的业务逻辑。 In addition, your company wants there to be only one unified endpoint, myservice.com for the service. 此外,您的公司希望只有一个统一的端点,myservice.com用于该服务。 In this case, you need to set up a reverse proxy as the unified endpoint. 在这种情况下,您需要将反向代理设置为统一端点。 The proxy takes the url myservice.com, and rewrites the url of incoming requests so that requests from UK(determined by source ip) go to uk.myservice.com and requests from German go to de.myservice.com. 代理接受url myservice.com,并重写传入请求的url,以便来自UK的请求(由source ip确定)转到uk.myservice.com,来自德语的请求转到de.myservice.com。 From the view of a client from UK, it never knows the response is actually generated from uk.myservice.com. 从英国客户的角度来看,它永远不知道响应实际上是从uk.myservice.com生成的。

In this case, the load of request traffic to the service is actually balanced to servers on uk.myservice.com and de.myservice.com as a side effect. 在这种情况下,对服务的请求流量的负载实际上与uk.myservice.com和de.myservice.com上的服务器平衡,作为副作用。 So we normally don't call it used as a load balancer, just say it as a reverse proxy. 因此,我们通常不会将其称为负载均衡器,只需将其称为反向代理即可。

But lets say if your company uses the same policy for all countries, and has 2 servers, a.myservice.com and b.myservice.com, only for the reason that the work load is to heavy for one server machine. 但是,假设您的公司对所有国家/地区使用相同的策略,并且有2台服务器,a.myservice.com和b.myservice.com,只是因为一台服务器计算机的工作负载很重。 In this case, we normally call the reverse proxy as load balancer to emphasize the reason why it is being used. 在这种情况下,我们通常将反向代理称为负载均衡器,以强调其使用的原因。

Here is the basic definition: 这是基本定义:

Reverse Proxy is a proxy host, that receives requests from a client, and sends it to one of the servers behind itself. 反向代理是一个代理主机,它接收来自客户端的请求,并将其发送到自身后面的一个服务器。 Nginx and apache httpd are commonly used as reverse proxies. Nginx和apache httpd通常用作反向代理。 These are in the administrative network of the web server that a servers a request. 这些是服务器请求的Web服务器的管理网络。

This is in contrast with a (forward) Proxy, which sits in front of a client, and sends requests on behalf of a client to a web server. 这与位于客户端前面的(转发)代理相反,并代表客户端向Web服务器发送请求。 As an example, your corporate network address translator is a forward proxy. 例如,您的公司网络地址转换器是一个转发代理。 These are in the administrative network of the client from where the request originates. 它们位于发出请求的客户端的管理网络中。

Load balancing is a function performed by reverse proxies. 负载平衡是由反向代理执行的功能。 The client requests are received by a load balancer, and the load balancer tries to send that request to one of the nodes (hosts) in the server pool, in an attempt to balance the load across various nodes. 负载均衡器接收客户端请求,并且负载均衡器尝试将该请求发送到服务器池中的一个节点(主机),以尝试平衡各个节点之间的负载。

I see both of them as a functionality of a HTTP/Web Server. 我将它们都视为HTTP / Web服务器的功能。

Load balancer's job is to distribute the workload between servers node in a way that makes the best use of it. 负载均衡器的工作是以最充分利用它的方式在服务器节点之间分配工作负载。

Reverse proxy is a interface for external world ,forwarding request to a server node (even when we have a single node) Its other use cases are caching of static content ,compression etc 反向代理是外部世界的接口,向服务器节点转发请求(即使我们有一个节点)其他用例是静态内容的缓存,压缩等

In simplest term: 最简单的说法:

A reverse proxy accepts a request from a client, forwards it to a server that can fulfill it, and returns the server's response to the client. 反向代理接受来自客户端的请求,将其转发到可以实现它的服务器,并将服务器的响应返回给客户端。

A load balancer distributes incoming client requests among a group of servers, in each case returning the response from the selected server to the appropriate client. 负载均衡器在一组服务器之间分配传入的客户端请求,在每种情况下将响应从所选服务器返回到适当的客户端。

But they sound pretty similar, right? 但它们听起来非常相似,对吗? Both types of application sit between clients and servers, accepting requests from the former and delivering responses from the latter. 这两种类型的应用程序都位于客户端和服务器之间,接受来自前者的请求并提供后者的响应。 No wonder there's confusion about what's a reverse proxy vs. load balancer. 难怪有什么是反向代理与负载均衡器的混淆。 To help tease them apart, let's explore when and why they're typically deployed at a website. 为了帮助他们分开,让我们探讨他们通常在网站上部署的时间和原因。


Load Balancing 负载均衡


Load balancers are most commonly deployed when a site needs multiple servers because the volume of requests is too much for a single server to handle efficiently. 当站点需要多个服务器时,最常部署负载平衡器,因为请求量太大,单个服务器无法有效处理。 Deploying multiple servers also eliminates a single point of failure, making the website more reliable. 部署多个服务器还可以消除单点故障,从而使网站更加可靠。 Most commonly, the servers all host the same content, and the load balancer's job is to distribute the workload in a way that makes the best use of each server's capacity, prevents overload on any server, and results in the fastest possible response to the client. 最常见的是,服务器都承载相同的内容,负载均衡器的工作是以最佳利用每个服务器容量的方式分配工作负载,防止任何服务器过载,并最快地响应客户端。

Reverse Proxy 反向代理

Whereas deploying a load balancer makes sense only when you have multiple servers, it often makes sense to deploy a reverse proxy even with just one web server or application server. 虽然部署负载均衡器只有在拥有多台服务器时才有意义,但即使只有一台Web服务器或应用服务器,部署反向代理通常也是有意义的。 You can think of the reverse proxy as a website's “public face.” Its address is the one advertised for the website, and it sits at the edge of the site's network to accept requests from web browsers and mobile apps for the content hosted at the website. 您可以将反向代理视为网站的“公共面孔”。它的地址是为网站广告的地址,它位于网站的网络边缘,接受来自网络浏览器和移动应用程序的请求,用于托管在网站。

more details... 更多细节...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM