preface

This article was finished before, but after my boss read it, the evaluation of this article is: the writing is good, the sentence is smooth, the typesetting is ok, but what the agent is still not clear? That’s why I feel like I failed, and that’s why I have this one.

I will try to explain the concept of “agency” to the general public. Explain “forward proxy” and “reverse proxy” from a professional perspective.

Conceptual instantiation

Before I get to the idea of agency let me make an analogy. That’s how I explain it to an adult.Luckily I was quick on my feet, or this month’s pocket money would have saved me from a knife. But how can I explain it? It’s nerve-racking for people who have no programming language background to understand.

In the absence of thoughts, she suddenly asked me if I had eaten for dinner? Isn’t that a good example?

After explaining for so long, I don’t know whether I really understand, or because I am too sleepy. But I have money for meat.

Let’s take a closer look at “forward proxies” and “reverse proxies.”

concept

Look at the illustration first to get a general idea.

Forward Proxy:

To get content from the original server, the client sends a request to the agent and specifies the target (the original server). The agent then forwards the request to the original server and returns the content to the client. The client can use the forward proxy.

Reverse Proxy:

A proxy server receives the Internet connection request, forwards the request to the Intranet server, and returns the result to the Internet client. In this case, the proxy server acts as a reverse proxy server.

Let me distill the characteristics of each.

The characteristics of

Forward agent

  1. Acting customers;
  2. Hide the real client, send and receive requests for the client, so that the real client is invisible to the server;
  3. All users on a LAN may be forward propped by a server that handles HTTP requests.
  4. The forward proxy server communicates with the server.

The reverse proxy

  1. Proxy server;
  2. Hide the real server, send and receive requests for the server, so that the real server is invisible to the client;
  3. Load balancing servers that distribute user requests to idle servers;
  4. This means that the user communicates with the load balancing server directly, that is, the user obtains the IP address of the load balancing server when resolving the server domain name.

In common

  1. Both serve as the middle layer between the server and the client
  2. Both can enhance Intranet security and prevent Web attacks
  3. Can do caching mechanism

Having said that, let’s talk about the application scenarios of agents at work.

The practical application

Nginx server

The Nginx server has many functions, such as reverse proxy, load balancing, static resource server, and so on.

The client could have accessed the server directly through HTTP, but we can add an Nginx server in the middle. The client requests the Nginx server, and the Nginx server requests the application server, and then returns the results to the client, which is the reverse proxy server.

Configure the reverse proxy in the configuration of the virtual host

Server {listen 8080; Server_name 192.168.1.1; Root /data/toor; Error_page 502 404 /page/404.html; # error page location ^~ / API / {# use/API/proxy proxy_pass value proxy_pass http://192.168.20.1:8080; # proxied application server HTTP address}}Copy the code

The previous simple configuration can implement the reverse proxy function.

Of course, reverse proxy can also deal with cross-domain problems. In Vue, proxyTable can be used for related configuration to solve the problems caused by cross-domain problems. The configuration is as follows:

. ProxyTable: {'/weixin: {target: 'http://192.168.48.11:8100/', / / interface domain secure: ChangeOrigin: true for HTTPS interfaces. PathRewrite: {'^/weixin': "}},},...Copy the code

Configure load balancing

Upstream my {server 192.168.2.1:8080 weight=1 max_fails=2 fail_timeout=30s; Server 192.168.2.2:8080 weight=1 max_fails=2 fail_timeout=30s; Server 192.168.2.3:8080 weight=1 max_fails=2 fail_timeout=30s; Server 192.168.2.4:8080 weight=1 max_fails=2 fail_timeout=30s; If the host fails two attempts within 30 seconds, the host will be considered unavailable.Copy the code

Load balancing refers to request/data polling spread over multiple servers. The key to load balancing is evenness.

You can also use ip-hash to allocate requests to a fixed server based on the hash value of the client IP address.

In addition, the hardware configuration of the server may be different and the configured server can handle more requests, which can be controlled by the weight parameter.

The above.

Front-end dictionary series

The Front End Dictionary series will continue to be updated, and in each issue I will cover a topic that comes up frequently. I would appreciate it if you could correct any inpreciseness or mistakes in the reading process. I will be delighted if I learn something from this series.

If you think my article is good, you can follow my wechat public account, which will reveal the plot in advance.

portal

  1. Solution to the rolling penetration problem